note 35691 deleted from function.date by didou

From: Date: Thu, 11 Sep 2003 10:18:35 +0000
Subject: note 35691 deleted from function.date by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-56060@lists.php.net to get a copy of this message
Note Submitter: jpenn at cheetah-soft dot com ---- In reply to 'SARGe at poopshovel dot com' post Why make things so hard? What you have there can be summed up with: <code> // Date And Days $from_date = '2003-08-27'; $days = 14; // Create Start UTStamp $start = strtotime( $from_date . '-' . $days . ' days' ); // Create End UTStamp $end = strtotime( $from_date . '+' . $days . ' days' ); echo( date( 'Y-m-j', $start ) ); // outputs -> 2003-08-13 echo( date( 'Y-m-j', $end ) ); // outputs -> 2003-09-10 </code> I used 14 as the days + and -, but using strtotime() as above, you can use any amount of days, weeks, months, years, etc. (after the epoch and before something like 2038 or somewhere around there) with no need to worry about leap year and the other factors.

« previous php.notes (#56060) next »