Re: dd/mm/yyyy Date Compare Problem



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.
.



Relevant Pages

  • Re: DateFormat - String Manipulating
    ... >for my indexserver I need this format: ... The latter form must be YYYY/MM/DD, but the former could be MM.DD.YYYY ... string yyyy/mm/dd - so consider:- ...
    (microsoft.public.scripting.vbscript)
  • Date problems
    ... I am using dates with the format ... yyyy/mm/dd in a Genealogy worksheet. ... When I input dates in the 1900 range I get all sorts of problems .... ...
    (microsoft.public.excel.setup)
  • Re: How can i save a date from vb.net to a dbf file?
    ... strict date format, {^YYYY/MM/DD} ... Enterprise Development with VS .NET, UML, AND MSF ... and I realized that it's the date format problem. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Problem of Date with MS Access
    ... My regional setting has to be dd/mm/yyyy. ... How can I change the MS access to yyyy/mm/dd in the Period column. ... there is no such format in the drop down box. ...
    (microsoft.public.inetserver.asp.db)
  • Formatting Dates
    ... 19990412 (yyyy/mm/dd). ... I would then like to format the ... column to display the field as (mm/dd/yyyy) but when I ...
    (microsoft.public.excel.worksheet.functions)