SQL PHP HTML ASP JavaScript articles and free scripts to download
PHP Date

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-14:Tue
01-09-14:Mon
31-08-14:Sun
30-08-14:Sat
29-08-14:Fri
28-08-14:Thu
27-08-14:Wed
26-08-14:Tue
25-08-14:Mon
24-08-14:Sun
23-08-14:Sat
22-08-14:Fri
21-08-14:Thu
20-08-14:Wed
19-08-14:Tue
18-08-14: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>";
}

Number of User Comments : 5


Google+
Click for more tutorial on Date & Time functions and Applications


More On Date Object
bhanu30-09-2009
thank you for help.it very help
siswoutomo28-12-2009
Very good this post, thank lot of
James21-04-2010
Does this work if the date is 4th of January (for example)
smo02-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.
kalpana15-01-2013
thanks you so much.It was so helpful
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer