faqts : Computers : Programming : Languages : PHP : Function Libraries : Date and Time

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

28 of 31 people (90%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

How can I add 90 days to a date: like add 90 days to 7/23/2004 which is pulled from a text file?

Jul 24th, 2004 00:37
Philip Olson, Steve Wykpisz,


You first want to get the unix timestamp from the date as doing this
will make this a simple matter of addition.  Using mktime() is another
option.
Since the format you speak of is pretty common, let's do this:
<?php
  $date = '7/23/2004';
  $timestamp_current = strtotime($date);
  $timestamp_future  = $timestamp_current + (60*60*24*90);
  // The following will print 10/21/2004
  echo date('n/j/Y', $timestamp_future);
?>
See also: http://www.php.net/function.strtotime
          http://www.php.net/function.date
          http://www.php.net/function.mktime