
Question:
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
Solution: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.
Solution:2
this function lets you convert dates to timestamps with wich you could work: http://caioariede.com/arquivos/strtotime.js
Solution:3
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) { // ... }
Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
EmoticonEmoticon