Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need to Compare two dates
Message
Information générale
Forum:
Internet
Catégorie:
Javascript
Divers
Thread ID:
00570783
Message ID:
00570870
Vues:
22
This message has been marked as the solution to the initial question of the thread.
>Can someone show me the Java code needed to compare two dates that the user enters MM/DD/YYYY and ensure that one is not greater than another. So I have two date fields on a form and want to ensure that the second date is not greater than the first date and display a message to the user that it is an error.
>
>TIA

This should work:
function checkDates(date1Str, date2Str)
{
	var date1 = new Date(date1Str.substring(6,10),
                            date1Str.substring(0,2)-1,
                            date1Str.substring(3,5));
	var date2 = new Date(date2Str.substring(6,10),
                            date2Str.substring(0,2)-1,
                            date2Str.substring(3,5));

	if (date1.valueOf() > date2.valueOf())
		alert('Date Start cannot be greater than Date End');

}
With the assumption that the dates will always be in mm/dd/yyyy format. HTH
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform