0

$currentTime = date("h:i a");

Im storing time in my db like this... $timeEnd = date("h:i a"); which outputs "07:15 pm".

I need to compare $expireTime to $currentTime.

$sql2 = "UPDATE id SET expired = '1' WHERE timeEnd <= '".$currentTime."' AND date = '".$currentDate."'";

This code works except it's not considering am/pm... what am I doing wrong?

EDIT: So it seems one answer would be to insert a 24 hour format into the db, which makes sense... is there anyway to make this work though? unix timestamp? strototime in the query?

  • Your time format is not doing you any favors. I don't think I'd be passing any php variables into the query -- SQL can generate date and time values on its own. The first step is to reformat your time format. In other words, use military time instead using am/pm. – mickmackusa Jan 15 '21 at 04:22
  • Does this answer your question? [How to compare two dates in php](https://stackoverflow.com/questions/8722806/how-to-compare-two-dates-in-php) – manqlele Jan 15 '21 at 04:27
  • The reason its formatted that way is because the user selects from a drop down menu. So i should convert it to another format before updating the db? – droppedNboosted Jan 15 '21 at 04:33
  • Definitely. The end user's format does not need to match the db format. The text of the ` – mickmackusa Jan 15 '21 at 04:34
  • You're right. Thats the best way, thank you – droppedNboosted Jan 15 '21 at 04:38
  • After formatting the date and time, this query should solve your need, since time is stored on the DB using 24H format as default. `UPDATE id SET expired = '1' WHERE time(timeEnd) <= '".$currentTime."' AND date(date) = '".$currentDate."'";` – hmg Jan 15 '21 at 04:56

0 Answers0