group-icon
PHP Programming
Group for all things PHP, Coding Help, Problems and Solutions
101 Members
Join this group to post and comment.
DHIRAJ LOTLIKAR
DHIRAJ LOTLIKAR
Information Technology
04 Feb 2019

What are PHP time and date function?

Dates are so much part of everyday life that it becomes easy to work with them without thinking. PHP also provides powerful tools for date arithmetic that make manipulating dates easy.

PHP's time() function gives you all the information that you need about the current date and time. It requires no arguments but returns an integer.

The integer returned by time() represents the number of seconds elapsed since midnight GMT on January 1, 1970. This moment is known as the UNIX epoch, and the number of seconds that have elapsed since then is referred to as a time stamp.

Consider the following code,

print time();

?>

The above code will produce the following result,

1480930103

This is something difficult to understand. But PHP offers excellent tools to convert a time stamp into a form that humans are comfortable with.

The function getdate() optionally accepts a time stamp and returns an associative array containing information about the date. If you omit the time stamp, it works with the current time stamp as returned by time().

Converting a time stamp with date() function

The date() function returns a formatted string representing a date. You can exercise an enormous amount of control over the format that date() returns with a string argument that you must pass to it.

date( format, timestamp)

The date() optionally accepts a time stamp if omitted then current date and time will be used. Any other data you include in the format string passed to date() will be included in the return value.


Shruthi Pillai
Shruthi Pillai
Information Technology
1mo ago

PHP date function is an in-built function that simplify working with date data types. The PHP date function is used to format a date or time into a human readable format. 

Syntax is date(format,[timestamp]);