Re: dd/mm/yyyy Date Compare Problem
- From: Dr John Stockton <jrs@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 28 Apr 2006 21:20:24 +0100
JRS: In article <1146231504.278277.155500@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
, dated Fri, 28 Apr 2006 06:38:24 remote, seen in
news:comp.lang.javascript, Assimalyst <c_oxtoby@xxxxxxxxxxx> posted :
I have a working script that converts a dd/mm/yyyy text box date entry
to yyyy/mm/dd
AFAICS, you do not. It converts "dd/mm/yyyy" to a Date Object, but
yyyy/mm/dd is not involved.
and compares it to the current date, giving an error
through an asp.net custom validator, it is as follows:
function doDateCheckNow(source, args)
{
var oDate = document.getElementById(source.controltovalidate); //
dd/mm/yyyy
Don't let your posting agent line-wrap; posted code should be directly
executable.
var arrDate = oDate.value.split("/");
var useDate = new Date(arrDate[2], arrDate[1]-1, arrDate[0]); //
yyyy/mm/dd
or
var useDate = // via yyyy/mm/dd
new Date(oDate.value.replace(/(..).(..).(....)/, "$3/$2/$1"))
var today = new Date();
if (useDate <= today)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
Should be args.IsValid = useDate <= today
}
function doDateCheckDod(dodTxtBx, dobLbl, args)
{
// Convert DOD to javascript date format
var oDodDate = dodTxtBx; // dd/mm/yyyy
var arrDodDate = oDodDate.value.split("/");
var useDodDate = new Date(arrDodDate[2], arrDodDate[1],
arrDodDate[0]); // yyyy/mm/dd
// Convert DOB to javascript date format
var oDobDate = dobLbl; // dd/mm/yyyy
var arrDobDate = oDobDate.value.split("/");
var useDobDate = new Date(arrDobDate[2], arrDobDate[1],
arrDobDate[0]); // yyyy/mm/dd
Repeated code should generally be put in a function. When that is done,
and the function is small, temporary local variables do not need long
names.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
.
- References:
- dd/mm/yyyy Date Compare Problem
- From: Assimalyst
- dd/mm/yyyy Date Compare Problem
- Prev by Date: Cookie problem! Getting error when passing the expire date.
- Next by Date: getting and setting scroll-y position
- Previous by thread: Re: dd/mm/yyyy Date Compare Problem
- Next by thread: dynarch calendar, rows of inputs, init
- Index(es):
Relevant Pages
|