Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/183080-if-statement-for-a-christmas-card/
Share on other sites

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";
}
?>

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 :P

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";
}
?>

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.