Scarlet Posted November 27, 2009 Share Posted November 27, 2009 This has to be one of the most random questions on here.... Basically I want to make a novelty Christmas card for someone who is a PHP programmer. Problem is that I am not one. What I want is a fake script that effectively says 'if the date is Christmas, display Merry Christmas'. The closest I have found is..... The following example will output "Have a nice weekend!" if the current day is Friday: <?php $d=date("D"); if ($d=="Fri") echo "Have a nice weekend!"; ?> So can I change ("D") to ("D, d M Y") and ("Fri") to ("Fri, 25 Dec 2009")? Obviously it will then say echo "Merry Christmas". Or would that just not work? Pathetic, I know. But the thought is there. I have searched a few forums, but I haven't seen anyone doing something the same as this. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/183080-if-statement-for-a-christmas-card/ Share on other sites More sharing options...
razta Posted November 27, 2009 Share Posted November 27, 2009 Looks like it should work to me, give it a try. Quote Link to comment https://forums.phpfreaks.com/topic/183080-if-statement-for-a-christmas-card/#findComment-966234 Share on other sites More sharing options...
abazoskib Posted November 27, 2009 Share Posted November 27, 2009 This has to be one of the most random questions on here.... Basically I want to make a novelty Christmas card for someone who is a PHP programmer. Problem is that I am not one. What I want is a fake script that effectively says 'if the date is Christmas, display Merry Christmas'. The closest I have found is..... The following example will output "Have a nice weekend!" if the current day is Friday: <?php $d=date("D"); if ($d=="Fri") echo "Have a nice weekend!"; ?> So can I change ("D") to ("D, d M Y") and ("Fri") to ("Fri, 25 Dec 2009")? Obviously it will then say echo "Merry Christmas". Or would that just not work? Pathetic, I know. But the thought is there. I have searched a few forums, but I haven't seen anyone doing something the same as this. Thanks! That would only work on Christmas day. Maybe you should make a card that would work by looking at it on any day? <?php $xmas = mktime(0, 0, 0, 12, 25, 2009); $today = time(); if($xmas == $today) echo "Merry Christmas fool!"; else { $diff = $xmas-$today; $days_left = floor($diff/(60*60*24)); echo "There are only ".$days_left." days left till Christmas"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/183080-if-statement-for-a-christmas-card/#findComment-966312 Share on other sites More sharing options...
Scarlet Posted November 27, 2009 Author Share Posted November 27, 2009 Yes, I knew it would only work on the one day, but that was as simple as I could get it! But I do see the logic in your idea. And now I'm learning what mktime and floor do, lol. Thank you so much! I would say perhaps I'll get in to PHP yet, but it all seems too logical for me Quote Link to comment https://forums.phpfreaks.com/topic/183080-if-statement-for-a-christmas-card/#findComment-966387 Share on other sites More sharing options...
the-botman Posted November 27, 2009 Share Posted November 27, 2009 Hi .. is there a way this code can be added without using 2009 so we dont have to update the code every year Thanks in advance Zain Quote Link to comment https://forums.phpfreaks.com/topic/183080-if-statement-for-a-christmas-card/#findComment-966406 Share on other sites More sharing options...
the-botman Posted November 27, 2009 Share Posted November 27, 2009 would this work? <?php $year = date('Y'); $xmas = mktime(0, 0, 0, 12, 25, $year); $today = time(); if($xmas == $today) echo "Merry Christmas fool!"; else { $diff = $xmas-$today; $days_left = floor($diff/(60*60*24)); echo "There are only ".$days_left." days left till Christmas"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/183080-if-statement-for-a-christmas-card/#findComment-966409 Share on other sites More sharing options...
Anzeo Posted November 27, 2009 Share Posted November 27, 2009 would this work? <?php $year = date('Y'); $xmas = mktime(0, 0, 0, 12, 25, $year); $today = time(); if($xmas == $today) echo "Merry Christmas fool!"; else { $diff = $xmas-$today; $days_left = floor($diff/(60*60*24)); echo "There are only ".$days_left." days left till Christmas"; } ?> Looks like valid code to me Quote Link to comment https://forums.phpfreaks.com/topic/183080-if-statement-for-a-christmas-card/#findComment-966427 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.