downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

date_parse> <date_offset_get
Last updated: Fri, 14 Aug 2009

view this page in

date_parse_from_format

(PHP 5 >= 5.3.0)

date_parse_from_formatRécupère les informations d'une date donnée

Description

array date_parse_from_format ( string $format , string $date )

Retourne un tableau associatif contenant des informations détaillées sur une date donnée.

Liste de paramètres

format

Format accepté par la fonction date() avec quelques ajouts.

date

Chaîne représentant la date.

Valeurs de retour

Retourne un tableau associatif avec des informations détaillées sur la date donnée.

Exemples

Exemple #1 Exemple avec date_parse_from_format()

<?php
$date 
"6.1.2009 13:00+01:00";
print_r(date_parse_from_format("j.n.Y H:iP"$date));
?>

L'exemple ci-dessus va afficher :

Array
(
    [year] => 2009
    [month] => 1
    [day] => 6
    [hour] => 13
    [minute] => 0
    [second] => 0
    [fraction] => 
    [warning_count] => 0
    [warnings] => Array
        (
        )

    [error_count] => 0
    [errors] => Array
        (
        )

    [is_localtime] => 1
    [zone_type] => 1
    [zone] => -60
    [is_dst] => 
)



add a note add a note User Contributed Notes
date_parse_from_format
voidless at qip dot ru
10-Apr-2009 12:56
Example of rewriting function for older PHP versions:

convert
April 8, 2009, 1:12 am
to
timestamp

<?php
function date2sql($str = ""){
$month_arr = array (
   
"January" => 1,
   
"February" => 2,
   
"March" => 3,
   
"April" => 4,
   
"May" => 5,
   
"June" => 6,
   
"July" => 7,
   
"August" => 8,
   
"September" => 9,
   
"October" => 10,
   
"November" => 11,
   
"December" => 12
);
preg_match('/([a-zA-Z]{3,9}) ([0-9]{1,2}), ([0-9]{4}),
([0-9]{1,2}):([0-9]{1,2}) ([ap])m/'
,$str,$matches2);
if (
$matches2[6]=="a") $hour = $matches2[4];
else
$hour = $matches2[4]+12;
if (
$hour==24) $hour=0;
return
mktime($hour,$matches2[5],0,
$month_arr[$matches2[1]],$matches2[2],$matches2[3]);
}
   
$time = date2sql("March 29, 2009, 12:12 pm");
    echo
"{$time}</br>\n";
?>

date_parse> <date_offset_get
Last updated: Fri, 14 Aug 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites