spacepoet Posted March 7, 2011 Share Posted March 7, 2011 Hi: I am working with a little bit of code, but not certain if my syntax is correct. Doesn't seem to be doing what I need it to do: <?php if (date <= "4/8/2011") echo "Event Details"; else echo "Default Text"; ?> Basically, I want to show "Event Details" if the date is before or on 4/8/2011. If it is after 4/8/2011, I want to show "Default Text" It seems to be doing the opposite. What am I missing? Link to comment https://forums.phpfreaks.com/topic/229909-if-date-is-less-than-or-equal-to/ Share on other sites More sharing options...
Maq Posted March 7, 2011 Share Posted March 7, 2011 Use the strtotime function first. Link to comment https://forums.phpfreaks.com/topic/229909-if-date-is-less-than-or-equal-to/#findComment-1184171 Share on other sites More sharing options...
spacepoet Posted March 7, 2011 Author Share Posted March 7, 2011 Hi: I tried it like this: <?php if (strtotime(date <= "4/8/2011")) echo "Event Details"; else echo "Default Text"; ?> But it is not working. When I change the date to 3/1/2011, it still displays "Event Details" Can you show me what you mean? Link to comment https://forums.phpfreaks.com/topic/229909-if-date-is-less-than-or-equal-to/#findComment-1184186 Share on other sites More sharing options...
MatthewJ Posted March 7, 2011 Share Posted March 7, 2011 if(time() <= strtotime("4/8/2011")) { echo "It is before 4/8/2011"; } else { echo "It is after 4/8/2011"; } Link to comment https://forums.phpfreaks.com/topic/229909-if-date-is-less-than-or-equal-to/#findComment-1184189 Share on other sites More sharing options...
Maq Posted March 7, 2011 Share Posted March 7, 2011 Can you show me what you mean? I posted a link to the manual, there are plenty of examples there. Matthew has given you one as well. Link to comment https://forums.phpfreaks.com/topic/229909-if-date-is-less-than-or-equal-to/#findComment-1184194 Share on other sites More sharing options...
spacepoet Posted March 7, 2011 Author Share Posted March 7, 2011 Hi: Thanks for the link and the code. Yes, it is working fine now. The help is appreciated! Link to comment https://forums.phpfreaks.com/topic/229909-if-date-is-less-than-or-equal-to/#findComment-1184225 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.