I have a set of date that i have stored in my database in varchar format. The reason for me using Varchar is because im using jquery datepicker.
Is there a way for me to compare the date with current date.
I have a set of date that i have stored in my database in varchar format. The reason for me using Varchar is because im using jquery datepicker.
Is there a way for me to compare the date with current date.
You can try to use datejs library.
You can parse your string using Date.parse
and then Date.compare
to compare two dates.
$.get('date.php', function(date) {
alert(Date.compare(Date.today(), Date.parse(date));
});
you can use getDate, getMonth and getFullYear to get date, month and year for your date stored in varchar and current and compare them individually. The solution is not so elegant but will work.
var dt = new Date('2011-01-11'); //replace this hard coded date with one from database
var todaydate = new Date() //todays date
//i have added +1 in getMonth as its index start from 0. so if month is Jan then it returns 0 instead of 1. Hence i added +1
if (dt.getDate() == todaydate.getDate() && dt.getMonth()+1 == todaydate.getMonth()+1 && dt.getFullYear() == todaydate.getFullYear())
{
alert('match');
}
else
{
alert('not match');
}
Also see this fiddle here