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.
21-05-13:Tue 20-05-13:Mon 19-05-13:Sun 18-05-13:Sat 17-05-13:Fri 16-05-13:Thu 15-05-13:Wed 14-05-13:Tue 13-05-13:Mon 12-05-13:Sun 11-05-13:Sat 10-05-13:Fri 09-05-13:Thu 08-05-13:Wed 07-05-13:Tue 06-05-13:Mon
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>";
}
|