phpretard Posted December 15, 2008 Share Posted December 15, 2008 I am setting a date in my DB with $current_day=date('m-d-Y'); I am looking for a way to check for that day or after and execute code accordingly. The code below does exactly what it should...but I need to somehow say "if $current_day or later" if ($row['enddate']=="$current_day"){ << Problem If Statement $loginMessage="<tr height=30><td colspan='2'><img src='images/exclaim.gif' border='0'> Your 30 Day Trial Period Expired ".$row['enddate']."</td></tr>"; } Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/137105-solved-date-help-please/ Share on other sites More sharing options...
Mchl Posted December 15, 2008 Share Posted December 15, 2008 How is the date stored in database (what data type)? echo $row['enddate']; to display actual format returned from database. Quote Link to comment https://forums.phpfreaks.com/topic/137105-solved-date-help-please/#findComment-716137 Share on other sites More sharing options...
phpretard Posted December 15, 2008 Author Share Posted December 15, 2008 varchar(10) // Probably Wrong I know echo $row['enddate']; = 12-15-2008 Quote Link to comment https://forums.phpfreaks.com/topic/137105-solved-date-help-please/#findComment-716140 Share on other sites More sharing options...
Maq Posted December 15, 2008 Share Posted December 15, 2008 if (strtotime($row['enddate'])==strtotime($current_day)) { Quote Link to comment https://forums.phpfreaks.com/topic/137105-solved-date-help-please/#findComment-716143 Share on other sites More sharing options...
Mchl Posted December 15, 2008 Share Posted December 15, 2008 varchar(10) // Probably Wrong I know echo $row['enddate']; = 12-15-2008 Extremely wrong. You will have nothing but trouble with that. Use DATE instead. It will require some changes in your script, but you will be spared a lot of work later. Quote Link to comment https://forums.phpfreaks.com/topic/137105-solved-date-help-please/#findComment-716145 Share on other sites More sharing options...
9three Posted December 15, 2008 Share Posted December 15, 2008 Right now your code says: if CURRENT DATE EQUALS to TODAY then { Execute commands } What you want is: if ($row['enddate'] >= "$current_day"){ //enddate is greater than current day $loginMessage="<tr height=30><td colspan='2'><img src='images/exclaim.gif' border='0'> Your 30 Day Trial Period Expired ".$row['enddate']."</td></tr>"; } Quote Link to comment https://forums.phpfreaks.com/topic/137105-solved-date-help-please/#findComment-716148 Share on other sites More sharing options...
Mchl Posted December 15, 2008 Share Posted December 15, 2008 Pardon me, but I believe it will be the other way round. We want to check if expiration date has already passed. Quote Link to comment https://forums.phpfreaks.com/topic/137105-solved-date-help-please/#findComment-716157 Share on other sites More sharing options...
Maq Posted December 15, 2008 Share Posted December 15, 2008 Pardon me, but I believe it will be the other way round. We want to check if expiration date has already passed. Mchl is right. It should be: if ($row['enddate'] Quote Link to comment https://forums.phpfreaks.com/topic/137105-solved-date-help-please/#findComment-716203 Share on other sites More sharing options...
Mchl Posted December 15, 2008 Share Posted December 15, 2008 Or, if the date was stored as DATE $query = "SELECT IF('enddate'<=NOW(),1,0) AS expired FROM table WHERE ...."; Quote Link to comment https://forums.phpfreaks.com/topic/137105-solved-date-help-please/#findComment-716209 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.