Jump to content

Archived

This topic is now archived and is closed to further replies.

barkster

Mysql Timestamp Plus Days?

Recommended Posts

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.

[code]
$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;
}
[/code]

Share this post


Link to post
Share on other sites
Try changing the script to:

[code]<?php


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

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

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


?>[/code]

Orio.

Share this post


Link to post
Share on other sites
You're trying to compare a date string with a timestamp, so of course it doesn't work. It's simpler if you do
[code]
<?php

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

?>
[/code]

Share this post


Link to post
Share on other sites

×

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.