Home Tutorial Php Phpdate strptime()


Share on Google+Share on Google+
Posted on: August 29, 2009 at 12:00 AM
The following example is about strptime used for parsing a date/time generated with strftime().

strptime() Function in PHP

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 of strptime() Function in PHP

strptime (date, format)

strptime() returns an array with the date parsed, or returns FALSE on error. Month and weekday names and other language dependent strings respect the current locale set with setlocale() (LC_TIME).

Parameters for strptime() Function in PHP

date - This is required string parameter to parse. 

format (string) - Also essential, it specifies the format used in date as it is used in strftime().

Example on strptime() Function in PHP:


$format = '%d/%m/%Y %H:%M:%S';

$strf = strftime($format);

echo "$strf\n";

print_r(strptime($strf, $format));


The above example will output something similar to:

28/08/2009 13:27:49



[tm_sec] => 49

[tm_min] => 27

[tm_hour] => 13

[tm_mday] => 3

[tm_mon] => 8

[tm_year] => 109

[tm_wday] => 6

[tm_yday] => 240

[unparsed] =>



Related Tags for strptime():

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 29, 2009

Recommend the tutorial

Advertisements Advertisements