sadmicrowave sadmicrowave - 1 month ago 12
Javascript Question

How to turn character date into integer JavaScript

I need a way to turn my 2 character string dates (i.e. '04/10/2010' & '05/24/2010') into an integers to see if one is greater than the other. If the user enters an end date that is less than the begin date I need to popup an "invalid date range" error.

Answer Source

From what you posted your real problem is:

I need to see if one date is greater than another in javascript/jquery.

If so all you need to use is the Javascript Date object (how to page here).

You can use it as follows:

var dateTextA = '04/10/2010';
var dateTextB = '05/24/2010';
var dateA = new Date(dateTextA);
var dateB = new Date(dateTextB);
if (dateA < dateB){
    alert("Your date is out of range!");

Note: Above code has been tested and works in IE7.

If you really feel you need an integer value, you can use the UTC function to get that.