views:

326

answers:

3

Hello, i have two String fields who represent Date in my page and i would to compare this two fields to know if my first date < second date

<tr>
<td align="right">First Date: </td>
<td align="left"> <html:text name="addPublicationForm" styleId="firstDate" property="firstDate" maxlength="10"/></td>
</tr>
<tr>
<td align="right">Second Date: </td>
<td align="left"> <html:text name="addPublicationForm" styleId="secondDate" property="secondDate" maxlength="10"/></td>

A: 

Once you are able to parse those strings into a Date object comparing them is easy (Using the < operator). Parsing the dates will depend on the format. You may take a look at Datejs which might simplify this task.

Darin Dimitrov
i want to use the validator of jquery
Mercer
+1 for 100% correct answer. @downvote, please enlighten us for what is wrong here.
jAndy
@Mercer, what validato are you talking about? Are you referring to some plugin?
Darin Dimitrov
yes, the jquery.js and the jquery.validationEngine.js
Mercer
A: 

If you are also using jQuery ui, in particular datepicker, you can use $.datepicker.parseDate(format, string) to turn your date strings into a JavaScript Date object, which you can then compare using the standard < and >

gnarf
A: 

There is already a similar question like this. See it if you have not seen it. This could be helpful http://stackoverflow.com/questions/658522/age-from-date-of-birth-using-jquery

mohang