0

Possible Duplicate:
Compare 2 dates with JavaScript

Hi,
I'm working on form validation for my application and i want to know where i would be to start looking at to find date comparison eg a start date and an end date. The dates inputted in to my application are in the form: DD/MM/YYYY. Thanks in Advance,
Dean

Community
  • 1
  • 1
Dean
  • 8,668
  • 17
  • 57
  • 86
  • 3
    You may want to check this post http://stackoverflow.com/questions/492994/compare-2-dates-with-javascript – dave Jul 29 '10 at 20:20

3 Answers3

1

If you are using the Javascript Date object, you can simply do:

var startDate = new Date();
var endDate = getEndDate();

if (endDate < startDate)
    alert("Houston, we've got a problem!");

EDIT: Changed naming a bit just to stick to camelCase convention, even though I despise it.

TJ Koblentz
  • 6,908
  • 1
  • 17
  • 16
0

this function lets you convert dates to timestamps with wich you could work: http://caioariede.com/arquivos/strtotime.js

Christian Smorra
  • 1,756
  • 11
  • 13
0

First, you'll want to parse the text into Date objects, then use the language's built-in date comparison. For example:

var dateStr = document.getElementById('foo').value;
var date = Date.parse(dateStr);

var dateStr2 = document.getElementById('foo2').value;
var date2 = Date.parse(dateStr2);

if (date < date2) {
    // ...
}
Jacob
  • 77,566
  • 24
  • 149
  • 228