barkster Posted September 8, 2006 Share Posted September 8, 2006 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 https://forums.phpfreaks.com/topic/20118-mysql-timestamp-plus-days/ Share on other sites More sharing options...
Orio Posted September 8, 2006 Share Posted September 8, 2006 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 https://forums.phpfreaks.com/topic/20118-mysql-timestamp-plus-days/#findComment-88373 Share on other sites More sharing options...
king arthur Posted September 8, 2006 Share Posted September 8, 2006 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 https://forums.phpfreaks.com/topic/20118-mysql-timestamp-plus-days/#findComment-88400 Share on other sites More sharing options...
barkster Posted September 8, 2006 Author Share Posted September 8, 2006 Gracious, I'll try that Mr. Arthur. Link to comment https://forums.phpfreaks.com/topic/20118-mysql-timestamp-plus-days/#findComment-88609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.