How to display the date of yesterday and tomorrow by using
gmdate(“l F jS Y”)
for eg :
Today is Tuesday Jan 18th, 2005
I want to display :-
Tomorrow is Wednesday Jan 19th 2005
Yesterday was Monday Jan 17th 2005
How to display the date of yesterday and tomorrow by using
gmdate(“l F jS Y”)
for eg :
Today is Tuesday Jan 18th, 2005
I want to display :-
Tomorrow is Wednesday Jan 19th 2005
Yesterday was Monday Jan 17th 2005
try this little snippet of code
$date_format = 'l F jS Y';
$today = mktime();
$d = date('d', $today);
$m = date('m', $today);
$y = date('Y', $today);
$yesterday = mktime(0, 0, 0, $m, ($d - 1), $y);
$tomorrow = mktime(0, 0, 0, $m, ($d + 1), $y);
echo ' Yesterday - ' . gmdate($date_format, $yesterday) . '<br />';
echo ' Today - ' . gmdate($date_format, $today) . '<br />';
echo ' Tomorrow - ' . gmdate($date_format, $tomorrow) . '<br />';
An alternative method
$date_format = 'l F jS Y';
$today = strtotime('now');
$yesterday = strtotime('-1 day', $today);
$tomorrow = strtotime('+1 day', $today);
echo ' Yesterday - ' . gmdate($date_format, $yesterday) . '<br />';
echo ' Today - ' . gmdate($date_format, $today) . '<br />';
echo ' Tomorrow - ' . gmdate($date_format, $tomorrow) . '<br />';
It is displaying the wrong result.
Result :-
Yesterday - Sunday January 16th 2005
Today - Tuesday January 18th 2005
Tomorrow - Tuesday January 18th 2005
Please post the exact code you are using.
These are the results I get
Using mktime
Yesterday - Monday January 17th 2005
Today - Tuesday January 18th 2005
Tomorrow - Wednesday January 19th 2005
Using strtotime
Yesterday - Monday January 17th 2005
Today - Tuesday January 18th 2005
Tomorrow - Wednesday January 19th 2005
swdev’s 2nd version (using strtotime) works fine for me and gives the right dates, here it is again cleaned-up a little bit - try it and see:
<?php
$date_format = 'l F jS Y';
$yesterday = strtotime('-1 day');
$tomorrow = strtotime('+1 day');
echo ' Yesterday - ' . date($date_format, $yesterday) . '<br />';
echo ' Today - ' . date($date_format) . '<br />';
echo ' Tomorrow - ' . date($date_format, $tomorrow) . '<br />';
?>
Cheers,
Rich
SwDev alternative method works fine for me.
Thankyou all.
<?php
$date_format = ‘l F jS Y’;
$today = strtotime(‘now’);
$yesterday = strtotime(‘-1 day’, $today);
$tomorrow = strtotime(‘+1 day’, $today);
echo ’ Yesterday - ’ . gmdate($date_format, $yesterday) . ‘<br />’;
echo ’ Today - ’ . gmdate($date_format, $today) . ‘<br />’;
echo ’ Tomorrow - ’ . gmdate($date_format, $tomorrow) . ‘<br />’;
?>