I want a php script that shows time left for christmas, with a Christmas tree on the background size is 125x125 Please help me.
you could use strtotime(); to convert the date to a timestamp and calculate it from there like: <?php $christmas = strtotime('25 December 2008'); $now = time(); $timeleft = $christmas-$now; $daysleft = round((($timeleft/24)/60)/60); //probably... echo "There are $daysleft days left until christmas!"; ?> PHP: hope it helps
Bhuntay, I integrated lui2603's code above with some css and a Christmas tree background to see how it looks. http://www.kalinawebdesigns.com/countdown.php Only thing is the text doesn't stand out a lot, so you may have to find a different Christmas tree and play around with the css a bit.
Heres Mine: with Christmas tree in Background It shows (for example): Last Day the Tag "DAY" will be changed into Minutes and then Minutes into Seconds(which really looks cool) Copy and Paste this code in PHP File, and Include this file in any part of your PHP Page: <?php $d=date("d"); $m=date("m"); $now = strtotime("now"); $timeDiff = $time - $now; if($stl_days) { // assign days to $text if($stl_hours) { // assign hours to $text } } elseif($stl_hours) { // assign hours to $text if($stl_mins) { // assign minutes to $text } } elseif($stl_mins) { // assign minutes to $text if($stl_secs) { // assign seconds to $text } } elseif($stl_secs) { // assign seconds to $text } if($timeDiff > 0) { $stl_days = floor($timeDiff/60/60/24); $stl_hours = $timeDiff/60/60%24; $stl_mins = $timeDiff/60%60; $stl_secs = $timeDiff%60; if($stl_days) { $text = "Days Left: ".$stl_days . " Day(s)<br>"; if($stl_hours) { $text .= ",Time Left: " .$stl_hours . "Hour(s)(till next Day) "; } } elseif($stl_hours) { $text = $stl_hours . " Hour(s)"; if($stl_mins) { $text .= ",Time Left: " .$stl_mins . "Minute(s) "; } } elseif($stl_mins) { $text = $stl_mins . " Minute(s)"; if($stl_secs) { $text .= ",Time Left:" .$stl_secs . "Second(s) "; } } elseif($stl_secs) { $text = $stl_secs . " Second(s)"; } } else { $text = "Hope you Enjoyed Christmas!"; // notifies that the expiration date has passed } function showTimeLeft($time) { $now = strtotime("now"); $timeDiff = $time - $now; if($timeDiff > 0) { $stl_days = floor($timeDiff/60/60/24); $stl_hours = $timeDiff/60/60%24; $stl_mins = $timeDiff/60%60; $stl_secs = $timeDiff%60; if($stl_days) { $text = "Days Left: ".$stl_days . "Day(s)<br>"; if($stl_hours) { $text .= "Time Left: " .$stl_hours . "Hour(s)(till next Day) "; } } elseif($stl_hours) { $text = $stl_hours . " Hour(s)"; if($stl_mins) { $text .= ", " .$stl_mins . "Minute(s) "; } } elseif($stl_mins) { $text = $stl_mins . " Minute(s)"; if($stl_secs) { $text .= ", " .$stl_secs . "Second(s) "; } } elseif($stl_secs) { $text = $stl_secs . " Second(s)"; } } else { $text = "Hope you Enjoyed Christmas!"; } return $text; } $expTime = strtotime("19 September"); $text2= showTimeLeft($expTime); ?> <div style="background-image:url('http://img517.imageshack.us/img517/6531/christeo7.png');background-repeat:no-repeat;width:160px;height:125px;background-position:center center;" align="center"> <div style="background-color: #3979d9;opacity:.85;filter: alpha(opacity=85); -moz-opacity: 0.85;border:1px solid black;margin-top:30px;position:absolute;"> <?php print '<span style="color:maroon;">'.$text2."</span>"; ?> </div> </div> Code (markup): The one who likes it, don't forget to ADD REP
Hey lui2603, thank you very very much Rep added. Hey Colleen thank you sooo much, this is what I was looking for added a rep Can you share me the sourcecode please As always thanks mehdi, Thank you everyone thank you guys, I have added reps to all of you
Sorry if I come a bit late with this (I paused in between...) That might be quite simple to do: If you have some simple notions in programming, the ingredients are: - The date/time of the current day: $inittime=time(); PHP: - Christmas timestamp: $datexmas=strtotime('2008-12-25 00:00:00'); PHP: Let's avoid time and date function and let stick to traditional coding: Difference between these 2 dates: $timediff = $datexmas - $inittime; $days=intval($timediff/86400); $remaining=$timediff%86400; $hours=intval($remaining/3600); $remaining=$remaining%3600; $mins=intval($remaining/60); $secs=$remaining%60; PHP: Finally echoing the result: echo "<br>".$days.' days '.$hours.' hours '.$mins.' minutes and '.$secs.' seconds.'; PHP: You can see the result at http://www.webrickco.com/testdates.php The Christmas tree on the background should be a simple HTML matter.
nice script last one.............. reply 4 getting in touch............. ---------------------------------------------- www.ebookondemand.in
If there's anything that can make it dynamic, I mean seconds minutes all increasing and days decreasing.
I don't understand what you mean by: Is it not all suppose to decrease? Anyways, if you want it dynamic, then you have 2 solutions: - You keep it server side and add a simple Ajax request based on event timer request, - You turn it into a Javascript function only, taken care by the brower also based on a event timer. I would prefer the second one, no need to call the server to have a time delay display. And most of all, you'll get always the local time of the user, avoid to have a complex management of the time lag I did not introduce in my previous Reply. Just Answer this post if you need the javascript code.