RE: [PHP] Date/Time Arithmetic

From: Date: Wed, 11 Apr 2001 17:09:38 +0000
Subject: RE: [PHP] Date/Time Arithmetic
Groups: php.general 
Request: Send a blank email to php-general+get-48184@lists.php.net to get a copy of this message
> Is it possible to do some arithmetic with time/date values in PHP? > for example, to calculate: > today + 1050 days. > today - 7 days. > etc. > I mean, does PHP have functions to perform these operations? $oneDay = 86400; // number of seconds in a day // 60 seconds * 60 minutes * 24 hours $today = date( "U" ); // lookup the date() function $oneWeekAgo = $today - ( $oneDay * 7 ); $1050Days = $today + ( $oneDay * 1050 ); echo "The date for one week ago is: "; echo date( "F d, Y", $oneWeekAgo ); echo "1,050 days in the future is: "; echo date( "F d, Y", $1050Days ); The unix timestamp is an awesome tool for date arithmetic. Time arithmetic uses the same logic but on a smaller scale. $oneMinute = 60; // seconds $oneHour = 3600; // seconds; 60 seconds * 60 minutes Chris

« previous php.general (#48184) next »