Definition and Usage
The strptime() function parses a time/date generated with strftime().This function returns an array with the date parsed. The meaning of the returning array keys are:
- [tm_sec] - seconds (0-61)
- [tm_min] - minutes (0-59)
- [tm_hour] - hour (0-23)
- [tm_mday] - day of the month (1-31)
- [tm_mon] - months since January (0-11)
- [tm_year] - years since 1900
- [tm_wday] - days since Sunday (0-6)
- [tm_yday] - days since January 1 (0-365)
- [unparsed] - the date part which was not recognized using the specified format, if any
Syntax
strptime(date,format)
| Parameter | Description |
|---|---|
| date | Required. The string to parse (e.g. returned from strftime()) |
| format |
Required. Specifies the format used in the date:
|
Tips and Notes
Note: This function is not implemented on Windows platforms.Example
Example of both strftime() and strptime():
<?php
$format="%d/%m/%Y %H:%M:%S";
$strf=strftime($format);
echo("$strf");
print_r(strptime($strf,$format));
$format="%d/%m/%Y %H:%M:%S";
$strf=strftime($format);
echo("$strf");
print_r(strptime($strf,$format));
OUTPUT :
03/10/2005 13:23:44
Array
(
[tm_sec] => 44
[tm_min] => 23
[tm_hour] => 13
[tm_mday] => 3
[tm_mon] => 9
[tm_year] => 105
[tm_wday] => 0
[tm_yday] => 276
[unparsed] =>
)
Array
(
[tm_sec] => 44
[tm_min] => 23
[tm_hour] => 13
[tm_mday] => 3
[tm_mon] => 9
[tm_year] => 105
[tm_wday] => 0
[tm_yday] => 276
[unparsed] =>
)