Jump to content

Recommended Posts

I'm trying to see if a date pulled from the database is less than the current date.. I'm using this:

if ($row['date'] < date("Y-m-d")) {
'do stuff
} else {
'do other stuff
}

it doesn't seem to work.. how can I check to see if the date is older than today?

the format in the $row['date'] is yyyy-mm-dd (2006-05-22)
Link to comment
https://forums.phpfreaks.com/topic/10183-checking-if-a-date-is-less-than-today/
Share on other sites

[!--quoteo(post=376031:date=May 22 2006, 10:11 AM:name=djanim8)--][div class=\'quotetop\']QUOTE(djanim8 @ May 22 2006, 10:11 AM) [snapback]376031[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I'm trying to see if a date pulled from the database is less than the current date.. I'm using this:

if ($row['date'] < date("Y-m-d")) {
'do stuff
} else {
'do other stuff
}

it doesn't seem to work.. how can I check to see if the date is older than today?

the format in the $row['date'] is yyyy-mm-dd (2006-05-22)
[/quote]

try this instead (keep in mind that you must compare them as timestamps in PHP):
[code]
if (strtotime($row['date']) < time()) {
  // do stuff
} else {
  // do other stuff
}
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.