简体   繁体   中英

Getting the next date of a day in MySQL database (PHP)

I have a series of weekly events in a database along with the day they happen on (in full form, so: 'Monday', 'Tuesday' etc). I've successfully printed the events in a while loop ordered by today, tomorrow, etc, but I'd like to put the date in brackets next to each one.

I thought it might be a case of (mock code):

$today = date("l");
$todays_date = date("j M");

if (day == $today) {
    $date = $todays_date;
    }

else if (day == $today + 1) {
    $date = $todays_date + 1;
    }

else if (day == $today + 2) {
    $date = $todays_date + 2;
    }

etc...

But I'm not so sure. It'd be ideal if I could just have the date in the database, but this seems to go against the grain of what MySQL is about.

Also, I'd like to ideally format the date as: 11 Jun.

EDIT

Presumably it's also got to fit into my while loop somehow:

if($result && mysql_num_rows($result) > 0) { 
    while ($row = mysql_fetch_array($result)) { 
        $items[] = array($row[0]);
        echo "<option>" . $row[0] . "</option>";
        }         
}

You can use strtotime ?

echo "Today: ".date("j M");
echo "Tomorrow: ".date("j M", strotime("+1 day"));

您可以使用strtotime

echo strtotime("+1 day");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM