1

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.

user1852728
  • 161
  • 2
  • 6
  • 13

2 Answers2

0

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));
});
jcubic
  • 61,973
  • 54
  • 229
  • 402
  • Can you add some more content? At this point, it should have been a comment rather than an answer. I don't even see how it's related to the question. – John Dvorak Mar 14 '13 at 08:18
0

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

DevelopmentIsMyPassion
  • 3,541
  • 4
  • 34
  • 60