Jump to content

Mysql Timestamp Plus Days?


barkster

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]
Link to comment
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.
Link to comment
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]
Link to comment
Share on other sites

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.