Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird date("d")+1 1

Status
Not open for further replies.

SM777

Technical User
Mar 7, 2001
208
GB
I'm using the date("d") function to display the date for tomorrow and yesterday:

$tomorrow = date("d")+1 . '-' . date("M");
$yesterday = date("d")-1 . '-' . date("M");

So yesterday (31-May) I see that tomorrow is 32-May ! and today, I see yesterday displayed as 0-Jun

How do I display the dates correctly for tomorrow and yesterday when its the end / beginning of the month?



 
Using the functions mktime and date, you should be able to get the correct date.
$ytime = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")) - ((60 * 60) * 24);
$ttime = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")) + ((60 * 60) * 24);
$yesterday = date("d-M", $ytime);
$tomorrow = date("d-M", $ttime); //Daniel
 
<?php



$month = date(&quot;m&quot;);
$day = date(&quot;d&quot;);
$year = date(&quot;Y&quot;);

echo &quot;Today is $day $month $year<hr>&quot;;

echo &quot;last Monday: &quot;.date(&quot;d m Y&quot;, mktime(0,0,0,$month,$day+1-date(&quot;w&quot;,mktime(0,0,0,$month,$day,$year)),$year)).&quot;<br>&quot;;
echo &quot;next Friday: &quot;.date(&quot;d m Y&quot;, mktime(0,0,0,$month,$day+5-date(&quot;w&quot;,mktime(0,0,0,$month,$day,$year)),$year)).&quot;<br>&quot;;
echo &quot;<hr>&quot;;

echo &quot;Next week:<br>&quot;;
echo &quot;Monday is : &quot;.date(&quot;d m Y&quot;, mktime(0,0,0,$month,$day+8-date(&quot;w&quot;,mktime(0,0,0,$month,$day,$year)),$year)).&quot;<br>&quot;;
echo &quot;Friday is : &quot;.date(&quot;d m Y&quot;, mktime(0,0,0,$month,$day+12-date(&quot;w&quot;,mktime(0,0,0,$month,$day,$year)),$year)).&quot;<br>&quot;;

?> ***************************************
Party on, dudes!
[cannon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top