adzie Posted July 31, 2009 Share Posted July 31, 2009 Hello folks, Can anyone tell me whats wrong with this below. every entry shows as either expired or current but each row should show different answer. I want to show expired if $aarrep['1'] date is greater than 30 days. if ("DATE_SUB(CURDATE(),INTERVAL 30 DAY)" >= $aarrep['1']) { $status = "Expired"; } else { $status = "Valid"; } Link to comment https://forums.phpfreaks.com/topic/168340-if-curdateinterval-30-day/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 1, 2009 Share Posted August 1, 2009 That syntax most closely resembles SQL but that is not an SQL query or SQL if() logic, so you would need to show the context of how you are using that in your query and the double-quotes in the vicinity of the DATE_SUB() function are making it into a string, so it will be a little hard to compare the string "DATE_SUB(CURDATE(),INTERVAL 30 DAY)" with a value in $aarrep['1'] DATE_SUB() is a mysql function. It is used in a mysql query, not in php logic. Edit: And the php date_sub() function has a significantly different syntax. Link to comment https://forums.phpfreaks.com/topic/168340-if-curdateinterval-30-day/#findComment-888020 Share on other sites More sharing options...
adzie Posted August 1, 2009 Author Share Posted August 1, 2009 PFMaBiSmAd , Thanks for your advice. $aarrep[1'] gives me the date for the user in 2009-07-31. What I need to do is find out if that date is more than 28 days from today and either print expired or print valid. I have tried many different examples and none give me the result I'm looking for. What would be a correct route to follow. many thanks Link to comment https://forums.phpfreaks.com/topic/168340-if-curdateinterval-30-day/#findComment-888232 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.