/    Sign up×
Community /Pin to ProfileBookmark

Comparing two date values

Hi,

I was wondering if any one could help, i have two texfields on a form

Start Date
End date.

What I want to do is check the values, so if I put this 10/05/2007 in start date and then this in 15/04/2007 it would show an alert saying start date is after the end date and ask themt to change it.

The date format is set like this dd/mm/yyyy

any help or points in the right direction would be great. Thanks.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@vijirubaApr 23.2007 — Convert the start time and end time into unix time time format and then validate.
Copy linkTweet thisAlerts:
@ricpApr 23.2007 — You don't actually need to convert it to epoch time (.getTime() method) as comparing the two objects will do a straight comparison, like so:

<i>
</i>var foo = new Date(2005,1,1);
var bar = new Date(2006,1,1);

// leaving us with:

foo &gt; bar == false;
foo &lt; bar == true;


Obviously, if you wish to convert the time difference into days/weeks/etc then converting down to epoch, doing the math, then converting back up to the base you want it on, would probably be the best method.
×

Success!

Help @webfort spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...