[thelist] calculating a date

michael josephson mike at josephson.org
Sun Oct 15 06:09:00 CDT 2000


Hi,

First of all, first post to this list (I think) so hi all! Been lurking on 
here for a few weeks.

At 10:14 15/10/2000, you wrote:

>I have a given date in $year, $month and $day.
>Now I want to calculate a new date that is 7 days or 9 weeks (given as
>63 days) in the future.
>
>The language of choice is PHP in this case, but probably the pure
>algorithms would help, too.

What I normally do in this case is convert the date to a Unix timestamp 
(that is a big integer representing the number of seconds since January 1 
1970). You can then add the appropriate number of seconds for the time 
period you want (e.g. 7 days = 7 * 24 * 60 * 60 seconds) and convert back 
to the date format you need the result in.

In PHP the conversion to a Unix timestamp can be done with mktime() or 
gmmktime(). See http://www.php.net/manual/ref.datetime.php for details on 
these functions and the ones you'll need for converting back at the end.

Hope this helps. Let me know if you need any more details,

  - Michael
  >> http://www.josephson.org






More information about the thelist mailing list