I need to use php (or html or javascript, I guess, if that would work better) to create a message that displays the week before christmas, fourth of july, etc. How would I go about doing that? Thanks for your help.
here's one way to check if its one week before : if (date('d M') == '18 Dec') { echo "week before xmas"; } Code (markup): but that's just checking a single date, if you wanted to say countdown the days till xmas. this would work but I'm sure there's a better solution. As its the 24th, I switched Feb for Dec to test it. if(date('M') == 'Dec') { if((date('d') >= 18) && (date('d') <= 25)) { $days = 25 - date('d') ; echo "$days days till xmas"; } if(date('d') == '25') { echo "Merry Xmas"; } } Code (markup):
Try this script. $dates is an array that stores the dates you want the messages for (m-d). $me are messages for corresponding dates. $dates=array('02-27','12-25','07-04'); $t=time(); $me=array('test message', 'message for christmas', 'message for july 4'); $message=''; $count=0; foreach($dates as $v){ $v=explode('-',$v); $m=$v[0]; $d=$v[1]; $tt= mktime(0,0,0,$m,$d,date("Y")); if($t<$tt){ if( ($tt-$t)<=(7*24*3600) ){ $message=$me[$count]; } } } echo $message; Code (markup): Thanks
Thanks. I used the code below, but found I needed it to do more than I mentioned before. How would I calculate the date of a holiday like memorial day, so the week before the holiday it says "Memorial day is on May 25"? The actual date changes each year. I'd need to do it for Memorial Day, Labor Day, and Thanksgiving. Thanks for helping out someone who really doesn't know what they're doing but is trying to learn. $dates=array('02-27','12-25','07-04'); $t=time(); $me=array('test message', 'message for christmas', 'message for july 4'); $message=''; $count=0; foreach($dates as $v){ $v=explode('-',$v); $m=$v[0]; $d=$v[1]; $tt= mktime(0,0,0,$m,$d,date("Y")); if($t<$tt){ if( ($tt-$t)<=(7*24*3600) ){ $message=$me[$count]; } } } echo $message; PHP:
try this <?php $data = array("name" => "Holiday", "date" => "25-12-2010", "message" => "Yeah, it's holiday"); $current = strtotime(date("d-m-Y",time()); $target = strtotime($data['date']); $day = round(abs($target - $current) / (60*60*24),0); // 1 day before holiday if($day == 1){ echo $data['message']; } ?> PHP:
No, they didn't move memorial day. However, it's last Monday of May, so the actual numerical date changes. @guardian999 - I need to actually say the date, like 'Memorial day is on May 25', so I can't just have a generic message saying 'Yeah it's a holiday'. Thanks, though.
it was more of a comment on him using 12-25 as the date, just duplicated the code that was already posted. finding holidays with a moving date is a bit harder. and the process would depend on the holiday. but hey google is your friend and mine too. see if this helps you out : http://michaelthompson.org/technikos/holidays.php
Yeah, I understand each individually, I just have no idea how to put it together without messing the other up.