Countdown timer in php and javascript, for the world cup 2014

Visit this link to view the post: http://eyedealab.com/?p=2935
Posted on: 1 Comment
Countdowntimer

Are your counting the days too? Now this is an extremely easy solution to count down to the FIFA world cup 2014 with php or javascript.

Lets see how to do this in two ways.

First we get the exact date from the Official website. In numeric format the date will be 6.12.2014.

It is starting on June 12 2014. WOW!!!

COUNTDOWN WITH PHP

Now we will place the date month and year in the mktime section of the php code below:

<?php
$fifa2014 = mktime(0, 0, 0, 6, 12, 2014) ;
$now = time () ;
$result =($fifa2014-$now) ;
$daystoGO =(int) ($result/86400) ;
print "World Cup 2014 - $daystoGO days to go!";
?>

We have written “World Cup 2014 – ” before $daystoGO in the code, you can write some more text or change it as you like.

For php only code just add this code to your wordpress blog sidebar or posts if your blog is php-code enabled, or add this code directly to a page or post or sidebar template. If php is not working for your html only pages then the javascript code can come to your rescue.

COUNTDOWN WITH JAVASCRIPT

If you are not aware of php or it is not working on your html only page, just copy and paste the javascript code below to your page, see how we have added the occasion date in the “target” variable.

You can also add this section to your page before the end tag, to keep the page content clean!

<script language="javascript" type="text/javascript">
today  = new Date();
todayE  = today.getTime();
target = new Date("12 June, 2014");
targetE = target.getTime();
daystoGO = Math.floor(((targetE - todayE) / (60*60*24)) / 1000);
</script>

And add the following section to the area where you want the countdown output.

World Cup 2014 - <script>document.write(daystoGO);</script> days to go!

RESULT: World Cup 2014 – 381 days to go!

You can add this same code for Durgapuja, Diwali, Christmas, or New Year countdown too!


Priyanka Naskar Majumder - the Owner, Eyedea LAB. Graphic & Web Design Studio, lives in Kolkata, India. Interested in: Usability research, Graphic Design, Web Design & Development.

One response ↓





Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.