Jump to content


Photo

Mysql Timestamp Plus Days?


  • Please log in to reply
3 replies to this topic

#1 barkster

barkster
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 08 September 2006 - 01:33 PM

I have the worst time with dates and times.  I have a timestamp field that I need to add thirty days to and then check if it has expired against todays date/time.  Of course I can't get it to work. Here is what I have, any help would be appreciated.

$created = mysql_result($LoginRS, 0, 'CreateDate');
$created = date("Y-m-d H:i:s",$created);
$created = date('Y-m-d H:i:s',strtotime("+30 day", $created));
if($created < time()) {
    print "Expired";
    die;			
} else {
    print "Not Expired";
    die;
}


#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 08 September 2006 - 01:50 PM

Try changing the script to:

<?php


$created = mysql_result($LoginRS, 0, 'CreateDate');

$expire = strtotime("+30 day", $created));

if($expire < time()) {
    print "Expired";
    die;			
} else {
    print "Not Expired";
    die;
}


?>

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 08 September 2006 - 02:17 PM

You're trying to compare a date string with a timestamp, so of course it doesn't work. It's simpler if you do
<?php

$created = mysql_result($LoginRS, 0, 'CreateDate') ;
if($created < time() - 30 * 24 * 60 * 60) {
    print "Expired";
    die;			
} else {
    print "Not Expired";
    die;
}

?>

Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#4 barkster

barkster
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 08 September 2006 - 07:09 PM

Gracious, I'll try that Mr. Arthur.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users