Jump to content


Photo

Checking if a date is less than today...


  • Please log in to reply
1 reply to this topic

#1 djanim8

djanim8
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 22 May 2006 - 02:11 PM

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)

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 22 May 2006 - 02:13 PM

[!--quoteo(post=376031:date=May 22 2006, 10:11 AM:name=djanim8)--][div class=\'quotetop\']QUOTE(djanim8 @ May 22 2006, 10:11 AM) View Post[/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):
if (strtotime($row['date']) < time()) {
  // do stuff
} else {
  // do other stuff
}

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users