Re: subtracting Dates

From: Date: Tue, 01 May 2001 20:52:35 +0000
Subject: Re: subtracting Dates
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-51015@lists.php.net to get a copy of this message
> Hello, > For instance today is 05-01-2001 I would like to > determan the previous 7 days from that date. In VB > Date - 7 = 04-24-2001 I would like this to work for > any date using php. > Here is what I have so far... > $t = (date ("m-d-Y")); > echo $t; // output 05-01-2001 > echo "<br>"; > $r = $t - 7; > echo $r; //output -2 > but now $r returns -2 > How do I get $r to yesterdays date in this format. > 04-30-2001 see the php manual: (Function Reference / XV. Date and Time functions) a piece of description & examples about date() function: $tomorrow = mktime (0,0,0,date("m") ,date("d")+1,date("Y")); $lastmonth = mktime (0,0,0,date("m")-1,date("d"), date("Y")); $nextyear = mktime (0,0,0,date("m"), date("d"), date("Y")+1); date() with mktime() is more than perfect. After subtracting date parts with the help of date() you pass them to mktime... and you can deal with its arguments as integers.(see ie: $tomorrow).

« previous php.general (#51015) next »