> 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