views:

49

answers:

3

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

A: 

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

Christian Smorra
+1  A: 

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.

tjko
A: 

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