Home » PHP

PHP code to make a dynamic countdown timer

Here, we will learn how to design/make a dynamic countdown time using PHP code? Here, we are setting a last date time till countdown time will run.
Submitted by IncludeHelp, on October 15, 2017

Sometimes, we need to announce something on the website or want to wish any festival to our readers then we need a kind of timer (we can say, it is countdown timer) to be displayed on the website.

In this post, we are writing PHP code that will display a countdown timer for "Diwali" on the webpage.

In this code,

  • We are using a function strtotime() which is used to artificially generate the timestamp for a selected date and time.
  • We are defining date and time for festival “Diwali”, which is known as target date time, the value is "2017-10-19 12:00:00.
  • And, as a current date time we are using now which gives current date and time.

PHP code (with HTML) to display countdown timer

<!doctype html>
<html>
	<head>
		<title>PHP Countdown Timer</title>
	</head>

	<body>
		<?php
			$diwali = strtotime("2017-10-19 12:00:00"); // or whenever the diwali is
			$current=strtotime('now');
			$diffference =($diwali-$current);
			$days=floor($diffference / (60*60*24));
			echo "$days days left on Diwali";
		?>
		</br>
		<?php 
		$image_url='http://happydiwali2016imageshd.in/wp-content/uploads/2017/09/Diwali-GIF-1.gif';
		?>
		<img src="<?php echo $image_url;?>">
	</body>
</html>

Output

design a countdown time in PHP





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.