JonoB JonoB - 1 year ago 93
jQuery Question

How to check if input date is equal to today's date?

I have a form input with an id of 'date_trans'. The format for that date input (which is validated server side) can be any of:

  • dd/mm/yyyy

  • dd-mm-yyyy

  • yyyy-mm-dd

  • yyyy/mm/dd

However, before posting the form, I'd like to check if the date_trans field has a date that is equal to today's date. Its ok if the date taken is the client's date (i.e. it uses js), since I run a double check on the server as well.

I'm totally lost on how to do the date comparrison in jQuery or just plain old javascript. If it helps, I am using the jquery datepicker

Answer Source

Have you looked at datejs? (using the appropriate globalization pack to parse dd/mm/yyyy correctly)

Just pass the date in to its parse() method and compare with today's date.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download