Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

strptime()

Example

Parse a date/time string that was formatted using strftime().

<?php
$format=“%d/%m/%Y %H:%M:%S”;
$strf=strftime($format);
echo(“$strf”);
print_r(strptime($strf,$format));
?>

Definition and Usage

The strptime() function parses a date/time string formatted by strftime().

Note: This function is not available on Windows platforms!

Syntax

strptime(date, format)

Parameter Values

 

Parameter

Description

date

Required. The string to parse, typically generated by strftime().

format

Required. Specifies the format of the date string using format codes, such as:

  • %a – Abbreviated weekday name
  • %A – Full weekday name
  • %b – Abbreviated month name
  • %B – Full month name
  • %c – Preferred date and time representation
  • %C – Century number (year divided by 100, range 00 to 99)
  • %d – Day of the month (01 to 31)
  • %D – Same as %m/%d/%y
  • %e – Day of the month (1 to 31)
  • %g – Year without the century (like %G)
  • %G – 4-digit year corresponding to the ISO week number (see %V)
  • %h – Same as %b
  • %H – Hour in 24-hour format (00 to 23)
  • %I – Hour in 12-hour format (01 to 12)
  • %j – Day of the year (001 to 366)
  • %m – Month (01 to 12)
  • %M – Minute
  • %n – Newline character
  • %p – AM or PM based on the time
  • %r – Time in a.m. and p.m. notation
  • %R – Time in 24-hour notation
  • %S – Second
  • %t – Tab character
  • %T – Current time, equivalent to %H:%M:%S
  • %u – Weekday as a number (1 to 7), Monday=1 (Warning: On Sun Solaris, Sunday=1)
  • %U – Week number of the year, starting with the first Sunday as the first day of the first week
  • %V – ISO 8601 week number of the year (01 to 53), where week 1 is the first week with at least 4 days in the current year, with Monday as the first day of the week
  • %W – Week number of the year, starting with the first Monday as the first day of the first week
  • %w – Day of the week as a decimal, Sunday=0
  • %x – Preferred date representation without the time
  • %X – Preferred time representation without the date
  • %y – Year without the century (00 to 99)
  • %Y – Year including the century
  • %Z or %z – Time zone or name or abbreviation
  • %% – A literal % character

Technical Details

Return Value:

This function returns an array with the parsed date on success, or FALSE on failure. The keys in the array 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 portion of the date that was not recognized by the format, if any

PHP Version:

Available since PHP 5.1+