SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 

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.

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


Further readings
PHP Date & Time functions
PHP Date Time
Validating Date: Checking if date exist
PHP Date Today
PHP yesterday and previous 7 days from today
PHP Date Format
Time stamp generator
Date selection drop down list box
mktime function to generate time stamp
Difference in Two dates by using mktime function
Finding month, weekday, day of the year etc for any date value
Breaking the date string to get month date and year using array













bhanu30-09-2009
thank you for help.it very help
siswoutomo28-12-2009
Very good this post, thank lot of
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

Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
PHP Tutorials
Date & Time
PHP Monthly Planner
PHP Introduction
Loops & structure
Array
Date & Time
Functions
Form Handling
File Handling
Math Functions
String Functions
GD Functions
Comment Posting
Content Management
PHP & Ajax
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.