I retrieved date from database which is stored $str now I want to store Date & time in var countDownDate variable.
Here is my timeCounter.php file
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
p {
text-align: center;
font-size: 25px;
margin-top: 0px;
}
</style>
</head>
<body>
<p id="demo"></p>
<input type="hidden" id="dateFromDB" value="<?php echo $dateFromDB;?>">
<?php
include_once 'dbConnection.php';
if (@$_GET['q'] == 'quiz') {
$eid = @$_GET['eid'];
$time = @$_GET['time'];
$retrieve = mysqli_query($con, "SELECT time FROM quiz WHERE eid = '$eid'");
while($row = mysqli_fetch_array($retrieve)) {
$minutes = $row['time'];
//echo $minutes;
$hours = floor($minutes / 60);
$min = $minutes - ($hours * 60);
$sec = 1;
$str = $hours . ':' . $min . ':' . $sec;
echo $str;
}
}
?>
<script>
// Set the date we're counting down to set by teacher
var onlyDate = new Date().getDate();
var onlyMonth = new Date().getMonth();
var onlyYear = new Date().getYear();
//var countDownDate = new Date(onlyYear,onlyMonth,onyDate,0,0,0).getTime();
var countDownDate = new Date("May 25, 2021 22:39:59").getTime(); //set by teacher
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Output the result in an element with id="demo"
document.getElementById("demo").innerHTML = hours + ":" + minutes + ":" + seconds;
// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "Time Over";
}
}, 1000);
</script>
</body>
</html>