1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

I need a good php script that shows how many days left to Christmas.

Discussion in 'PHP' started by Bhuntay, Sep 18, 2008.

  1. #1
    I want a php script that shows time left for christmas, with a Christmas tree on the background size is 125x125 :) Please help me.
     
    Bhuntay, Sep 18, 2008 IP
    Mark.S likes this.
  2. bbrian017

    bbrian017 Well-Known Member

    Messages:
    2,990
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    170
    #2
    I would also be interested in something like this!
     
    bbrian017, Sep 18, 2008 IP
  3. lui2603

    lui2603 Peon

    Messages:
    729
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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 ;)
     
    lui2603, Sep 18, 2008 IP
    Bhuntay, bbrian017 and ebk like this.
  4. Colleen

    Colleen Illustrious Member

    Messages:
    6,777
    Likes Received:
    725
    Best Answers:
    1
    Trophy Points:
    430
    #4
    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.
     
    Colleen, Sep 18, 2008 IP
    Bhuntay and bbrian017 like this.
  5. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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 :)
     
    mehdi, Sep 18, 2008 IP
    ebk likes this.
  6. Bhuntay

    Bhuntay Banned

    Messages:
    837
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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 :)
     
    Bhuntay, Sep 18, 2008 IP
    Colleen likes this.
  7. webrickco

    webrickco Active Member

    Messages:
    268
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #7
    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.
     
    webrickco, Sep 18, 2008 IP
    ebk likes this.
  8. linkexchange1984

    linkexchange1984 Peon

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    nice script last one..............
    reply 4 getting in touch.............



    ----------------------------------------------
    www.ebookondemand.in
     
    linkexchange1984, Sep 18, 2008 IP
    ebk likes this.
  9. Bhuntay

    Bhuntay Banned

    Messages:
    837
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    0
    #9
    If there's anything that can make it dynamic, I mean seconds minutes all increasing and days decreasing.
     
    Bhuntay, Sep 18, 2008 IP
  10. webrickco

    webrickco Active Member

    Messages:
    268
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #10
    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.
     
    webrickco, Sep 19, 2008 IP