Presentation is loading. Please wait.

Presentation is loading. Please wait.

Session 3BBK P1 Module05-May-2007 : [‹#›] Date Manipulation.

Similar presentations


Presentation on theme: "Session 3BBK P1 Module05-May-2007 : [‹#›] Date Manipulation."— Presentation transcript:

1 Session 3BBK P1 Module05-May-2007 : [‹#›] Date Manipulation

2 Session 3BBK P1 Module05-May-2007 : [‹#›] 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.

3 Session 3BBK P1 Module05-May-2007 : [‹#›] 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 Session 3BBK P1 Module05-May-2007 : [‹#›] 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).’ ’; ?> Format strings: http://php.net/manual/en/function.date.phphttp://php.net/manual/en/function.date.php

5 Session 3BBK P1 Module05-May-2007 : [‹#›] 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 Session 3BBK P1 Module05-May-2007 : [‹#›] 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 Session 3BBK P1 Module05-May-2007 : [‹#›] 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 Session 3BBK P1 Module05-May-2007 : [‹#›] 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 Session 3BBK P1 Module05-May-2007 : [‹#›] HOE 7 : Handling Dates

10 Session 3BBK P1 Module05-May-2007 : [‹#›] Review Know what an integer UNIX date is. Can manipulate dates in PHP: creating, displaying, parsing from string data.


Download ppt "Session 3BBK P1 Module05-May-2007 : [‹#›] Date Manipulation."

Similar presentations


Ads by Google