Robson » Little Red Book » Tomorrow's date

Chapter 2 - Question 9

Given today's date in the form day, month, year, output tomorrow's date in the same format.

Solution 1

<?    // today's day, month and year    $day = date(d);    $month = date(m);    $year = date(Y);        // work out the timestamp of tomorrows date    // if this is the last day of month/year, it will loop round to the next month/year    $seconds = mktime(1,1,1,$month,$day+1,$year);      // output today and tomorrow    echo 'Today is ' . date('F jS, Y') . ', so tomorrow is ' . date('F jS, Y', $seconds); ?>

Which produces:

Today is July 8th, 2020, so tomorrow is July 9th, 2020

Solution 2

The strtotime() function is really useful for working out problems like this:

<?    // output today and tomorrow    echo 'Today is ' . date('F jS, Y') . ', so tomorrow is ' . date('F jS, Y', strtotime('Tomorrow')); ?>

Which produces:

Today is July 8th, 2020, so tomorrow is July 9th, 2020

Log

© 2004-20 robson | cc unless stated