Hi,

I am trying to write a code in php where I retrieve the DateTime from the database and find what time is it 15 minutes before the DateTime.

Such as

//Receiving the Start Time from the database.
$time1 = "2012-03-17 15:00:00";

//Reformating time to get the date 1hr or 1min or 15mins before Start Time.
$reminder = date("g:i", strtotime("-15 minutes", $time1));

//Print
echo $reminder;

But the only problem with the concept I have above is it prints out 7:00:09.

Can any one help me solve this issue please and thank you.

-Programmer12

Recommended Answers

All 3 Replies

Heres how i would do it:

echo date("Y-m-d H:i:s");
echo "<br/><br/>";
echo date("Y-m-d H:i:s",strtotime("-15 minutes",strtotime(date("Y-m-d H:i:s"))));

You should also watch if your mysql time going out of sync of your server time could be an issue, i hit a similar problem recently where the mysql was 3 hours out of sync with the server running the php script making things break and log incorrectly!

Oh yeah, I forgot about that. That might be the issue. I will need to change the PHP.ini file to say my
Timezone.

Thanks so much for your help! =) I really appreciate it

It worked! Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.