Hello Daniweb members.

Im looking to create a script which checks the current date and time (of web server to ensure a pre-set time zone) and display a message.

*What i'm aiming for the script/s to do.

*Check current date and time

*If day = eventDay BUT time = before start time
+Display count down clock

*If day = eventDay and time = after start time AND before event end time
+Display in progress

*If day = eventDay and time = after end time
+Display event ended

For example I currently have...

<?php
$dd = date('d/', time());
$mm = date('m/', time());
$yyyy = date('Y/', time());

$h = date('h:', time());
$m = date('i:', time());
$s = date('s', time());
$ampm = date('A', time());

echo "<br />";

echo $dd;
echo $mm;
echo $yyyy;

echo "<br />";
echo "<br />";

echo $h;
echo $m;
echo $s;
echo $ampm;

echo "<br />";
echo "<br />";

// EVENT STATUS //
if ($dd == 20 AND $h >= 4 AND $m >= 30)
{
if ($dd == 20 AND $h > 6 AND $m > 30)
{
Echo "This event finished at 6:30PM (GMT)";
}
else 
{
include "eventClock/eventClock.php";
}
}
else
{
echo "Event Coming Soon!";
}
// END EVENT STATUS //

I know this is a very basic script which kinda works in it's own way, but has many validation errors, So I manily asking for help and improvements. Would JavaSript be better as this needs to be constintly updated.

I've looked into cron jobs, but haven't found any that can replace a file on day @ time.

Thanks,
~KingGold171

NOTE , I will be editing this post to add more detail and information.

Recommended Answers

All 6 Replies

JavaScript would be a good choice for a countdown clock because you can actually see it counting down live. You could do it with a mix of JavaScript and PHP if you made ajax calls to a PHP script every 1-2 seconds.

jQuery has many plugins and I am sure there is a countdown plugin that someone has already made :)
http://www.designrazzi.com/2013/jquery-countdown-timer-scripts/

If you're going to use PHP then I would use the PHP DateTime class (if you're running php5 or greater that is).

An simple example:

<?php

$currentTime = new DateTime();
$eventStart = new DateTime('2013-11-28 9:30:00');
$eventEnd = new DateTime('2013-11-28 16:30:00');

$interval = $currentTime->diff($eventStart);

echo 'Current Time: ' . $currentTime->format('c') . '<br />';
echo 'Event Start: ' . $eventStart->format('c') . '<br />';
echo 'Event End: ' . $eventEnd->format('c') . '<br />';


if($currentTime < $eventStart){
    echo "coming soon <br />";
    printf('difference is %d year(s), %d day(s), %d hour(s), %d minute(s) <br />', $interval->y, $interval->d, $interval->h, $interval->i);
}

if($currentTime > $eventStart && $currentTime < $eventEnd){
    echo "in progress! <br />";
}

if($currentTime > $eventEnd){
    echo "it's over! Sorry! <br />";
}

?>

Hiya Pixelsoul,

Thank you for your responce.

The countdown script itself is already running smoothly via JQuery and Javascript, which im currently loking into ways of using this a basic API in which the PHP can be used to give the desired effect.

Working countdown clock as is: http://hilgayallstars.co.uk/ (left sidebar in upcoming event) This is where I would like to have the status of "In-Progress" or "Ended"

Dev-testing: http://thecreepersinn.com/KG171/ (all code testing is done here using a broken down copy of the main site)

(Your code snippit has been added)

If you need code-snippets these can be provided.

Thanks,
~KingGold171

Member Avatar for diafol

That particular clock I assume gets the start point from the server and then uses just js to count down. I also assume that when it reaches 0, it will fire off an ajax statement. Next to no PHP used, I assume again.

Hiya Diafol,

You are correct in the countdown clock using Javascript to get the current time from the users PC, then matching against the event start time to display the remaining time.

If you would like the souce code to look though and maby produce a proto-type or a starting point with the current system.

In the event I hit a brick wall I would resort to leaving the countdown at 0:0:0:0 then manually change by moving a pre-set php file. I can soon remote control server and move the file.

But ideally I would like to develop a automated system (with help or guideance from DaniWeb members who are happy to assist) to do this, then I can let it do it's thing without worry.

Any help will be greatfully recieved.

Thanks,
KingGold171

Member Avatar for diafol

I find coding countdowns extremely tedious. have a look at http://keith-wood.name/countdown.html and either use the jQ plugin or dissect the code and create one yourself. There are loads of examples of js countdown clocks with full source code.

The one in use is open source.

So just between now and tomorrows event i'll set up a PHP file to be moved into the web-folder, during the week before the next gig, I will do more research using some of the links provided by Diafol and Pixelsoul.

Thanks for your help and input so far.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.