I am trying to check if today's date is = 04/01/2013 in a PHP file. I have written the following JS Script. But I am getting some error. Dont know why. Please help
//This function will return if today is the date that we are looking for
function isToday($time) // midnight second
{
alert('1');
return (strtotime($time) === strtotime('today'));
}
Testing using the following:
if (isToday('2013-04-01 00:00:00.0') )
{
alert('Yes true');
}
else
{
alert("No false');
}
Please help how to compare today date = 04/01/2013. Thanks.
If you want to do a date/time compare in JavaScript, you will be best off checking this question asked previously:
Javascript equivalent of php's strtotime()?
That is a strtotime equivalent in JavaScript.
Here's a brief example:
var d = new Date("2013-04-01");
if(d == new Date()) {
alert('yes')
} else {
alert('no')
}
In PHP:
// Get the time
$serverDate = date('d/m/Y',time());
// Date to check against
$dateToCheck = '04/01/2013';
if($dateToCheck == $serverDate) {
alert('Yes true');
} else {
alert('No false');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.