Dates and times can be important elements in a web database application. PHP has the capability to recognize dates and times and handle them differently than plain character strings. Dates and times are stored by the computer in a format called a timestamp. Three important functions are date(), time() and strtotime().
PHP converts dates from your notation into a timestamp that the computer understands and from a timestamp into a format familiar to people. PHP handles dates and times with built-in functions.
The timestamp format is a Unix Timestamp, which is an integer that is the number of seconds from January 1, 1970, 00:00:00 GMT (Greenwich Mean Time) to the time represented by the timestamp. This format makes it easy to calculate the time between two dates, You just need to subtract one timestamp from the other.
The function that you will use most often is date, which converts a date or time from the timestamp format into a format that you specify. The general format is
$mydate = date("format", $timestamp);
If $timestamp isn’t included, the current time is obtained from the operating system and used. Thus, you can get today’s date with the following:
$today = date("Y/m/d");
The format is a string that specifies the date format that you want stored in the variable. The parts of the date can be separated by a hyphen (-), a dot (.), a forward slash (/), or a space.
Minutes and Seconds
You can assign a timestamp with the current date and time to a variable with the following statement:
$today = time();
Another way to store a current timestamp is with the statement:
$today = strtotime("today");
You can store specific timestamps by using strtotime with various keywords and abbreviations that are similar to English. For example,
$importantDate = strtotime("January 15 2018");
The strtotime statement recognizes the following words and abbreviations: