90 likes | 299 Views
Unix Epoch..?. The easiest way to handle dates in PHP is using UNIX timestamps.A UNIX timestamp is the number of seconds since the UNIX Epoch.The Epoch is 1st Jan 1970 00:00 GMT.. Get current time. Use the time() function to get current or relative time.<?php$now = time();$nextWeek = time()
E N D
1. Date Manipulation
2. Unix Epoch..? The easiest way to handle dates in PHP is using UNIX timestamps.
A UNIX timestamp is the number of seconds since the UNIX Epoch.
The Epoch is 1st Jan 1970 00:00 GMT.
3. Get current time Use the time() function to get current or relative time.
<?php
$now = time();
$nextWeek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs
?>
4. Display a time.. To display a time use the date() function along with a format string.
<?php
$nextWeek = time() + (7*24*60*60);
echo ‘Next week: ‘;
echo date(‘d-m-Y’,$nextWeek).’<br />’;
?>
Format strings: http://php.net/manual/en/function.date.php
5. String to timestamp To convert a string to date, use strtotime()
<?php
echo strtotime("now");
echo strtotime("10 September 2000");
echo strtotime("+1 day");
echo strtotime("+1 week");
echo strtotime("next Thursday");
echo strtotime("last Monday");
?>
6. String to timestamp Note that strtotime() assume a US date format on string such as mm/dd/yyyy, so some modifications may be required.
7. What about dates before 1970? Negative timestamps are not consistently supported in PHP.
Therefore we cannot use timestamps when using dates that might be before 1970.
8. The full information..
http://php.net/manual/en/ref.datetime.php
We have looked at a sub-selection of this information. If you want to do something with dates.. This is the place to start looking.
9. Review Know what an integer UNIX date is.
Can manipulate dates in PHP: creating, displaying, parsing from string data.