Countdown from specific date from mysql

Saturday, October 3, 2015

Well this is probably easy for you guys but i seriously cant make it work.

So What i would like to do is make a countdown based on the date from mysql and make it going down in live mode whithout the need to refresh.

Code:

<?php 
$date = strtotime($row_tournaments['date']);
$remaining = $date - time();
$days_remaining = floor($remaining / 86400);
$hours_remaining = floor(($remaining % 86400) / 3600);
$minutes_remaining = floor(($remaining % 3600) / 60);
$seconds_remaining = ($remaining % 60);
echo "<p>$days_remaining <span style='font-size:.3em;'>dias</span> $hours_remaining <span style='font-size:.3em;'>horas</span> $minutes_remaining <span style='font-size:.3em;'>minutos</span> $seconds_remaining <span style='font-size:.3em;'>segundos</span></p>";
?>

This works fine but i need to refresh so i can see the time going down.

So i find this answer,

Code:

<p id="counter"></p>


var counter = new Date(2015,10,10,20,25,30);
var counterElem = document.getElementById("counter");
setInterval(function()
{
counter.setSeconds(counter.getSeconds() - 1);
counterElem.innerHTML = counter.getDate()+" dias "+counter.getHours()+" horas "+counter.getMinutes()+" minutos "+counter.getSeconds()+" segundos";
},1000);


that actually works pretty fine but the problem is that the

new Date(2015,10,10,20,25,30)

only accepts this format and in my database the format of the date is

2015-10-06 06:17:18

And i dont how to convert.

Please help, if you guys have a better solution is well welcome.

Thanks for your time.

Cumps.


0 comments:

Post a Comment