Useful Date and Time Functions in PHP

Updated on     Kisan Patel

This post will explain you how to work with date and time in PHP. So here we have list out few PHP date and time functions.

parse_date function

PHP parse_date function takes a date string (date format accepted by strtotime().) and returns to you an associative array with details of the date.

print_r( date_parse("1990-05-26 18:24") );


time function

PHP time function return the current unix timestamps. It return the number of seconds that have passed since January 1, 1970.

echo time(); // print the 1422461315

strftime function

Obviously, Unix timestamps are not very user-friendly. For practical date formats, we need to use PHP strftime function.

You need to pass the string that tell strftime to how to format date and also pass a timestamp as the second parameter otherwise it will use the current time as the default.

echo strftime(" %a, %B %d, %Y"); // Wed, January 28, 2015


Leave a Reply