|
|
Getting yesterday and previous days date values
You must have seen how to get today date by using date function. By changing the date value we can get the dates of yesterday. Same way we can extend this to get date values of last 7 days. Or we can extend this to get dates between any to differences.
Let us find out the date value of yesterday.
$m= date("m"); // Month value
$de= date("d"); //today's date
$y= date("Y"); // Year value
echo date('d-m-y:D', mktime(0,0,0,$m,($de-1),$y));
Last seven days date value we can find out by using a for loop.
Here is the output of the code.
02-09-10:Thu 01-09-10:Wed 31-08-10:Tue 30-08-10:Mon 29-08-10:Sun 28-08-10:Sat 27-08-10:Fri 26-08-10:Thu 25-08-10:Wed 24-08-10:Tue 23-08-10:Mon 22-08-10:Sun 21-08-10:Sat 20-08-10:Fri 19-08-10:Thu 18-08-10:Wed
Here is the code.
$m= date("m");
$de= date("d");
$y= date("Y");
for($i=0; $i<=15; $i++){
echo date('d-m-y:D',mktime(0,0,0,$m,($de-$i),$y));
echo "<br>";
}
| | bhanu | 30-09-2009 |
|---|
| thank you for help.it very help | | siswoutomo | 28-12-2009 |
|---|
| Very good this post, thank lot of | | James | 21-04-2010 |
|---|
| Does this work if the date is 4th of January (for example) | | smo | 02-05-2010 |
|---|
| Yes this will work perfectly. Try with March 1st of 2008 also. For testing you need to change the date of your PC or server. |
|
|
|
|
|
|