The JavaScript
Date
constructor which takes a string is quite picky about the format of that string. Different browsers have varying support for different formats. Most browsers should support RFC2822 and ISO8601 date formats, but anything else is likely to cause problems.
If the format of the string you pass to the constructor is not supported, the
countDownDate
variable will be
undefined
. When you subtract the current date, you will get
NaN
.
You either need to make sure the date is formatted properly:
createCountDown('form<?php echo $row['id'];?>', <?php echo date_format(date_create($row['time_to_expire']), 'c') ;?>)
Or use a UNIX timestamp:
createCountDown('form<?php echo $row['id'];?>', <?php echo strtotime($row['time_to_expire']) ;?>)
Alternatively, if you know the format of the date, you can use
Moment.js[
^] to parse it on the client.