1 / 10

Date Manipulation

Date Manipulation. 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 1 st Jan 1970 00:00 GMT. Get current time. Use the time() function to get current or relative time. <?php

lixue
Download Presentation

Date Manipulation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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’,$now).’<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. HOE 7 : Handling Dates

  10. Review • Know what an integer UNIX date is. • Can manipulate dates in PHP: creating, displaying, parsing from string data.

More Related