Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Comparing Date display


Message #1 by Gui You <guiyou01@y...> on Mon, 10 Feb 2003 07:26:00 -0800 (PST)
Hi All,

I have a ASP script that has two input boxes: Start Date , End Date. Following is my codes:

StartDate = FormatTimeDate(Request.Form("startdate"),2) 

EndDate = FormatTimeDate(Request.Form("enddate"),2)

CurrentDate = FormatTimeDate(Now(),2)

If StartDate > EndDate Then 

Response.write "<script language=javascript>alert(""you entered is Not valid date."");</script>

Else if EndDate < CurrentDate Then

Response.write "<script language=javascript>alert(""you entered is exceeded date."");</script>

end if 

end if

= = = = = 

my problem is that the error msg does not display peroperly. So I want to know how to compare the dates. Thank you for your help in
advance.

YoYo



---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
Message #2 by Sam Clohesy <sam@e...> on Mon, 10 Feb 2003 15:44:50 -0000
Hi Gui-
Is this any good to you?(This checks if one date is earlier than the other-
you could tweak to your needs)


 //DATE CHECKING...........
  
  var strOrderDate,  strCompletionDate;
  
  if(FORM1.txtOrderDate.value == "")
  {
  alert("Please enter a report date.");
  FORM1.txtOrderDate.focus();
  return false;
  }
  else
  {
  strOrderDate = FORM1.txtOrderDate.value
  }
  
  if(FORM1.txtCompletionDate.value == "")
  {
  alert("Please enter a deadline.");
  FORM1.txtCompletionDate.focus();
  return false;
  }
  else
  {
  strCompletionDate = FORM1.txtCompletionDate.value
  }
  
  var dayOrderDate, monthOrderDate, yearOrderDate, dayCompletionDate,
monthCompletionDate, yearCompletionDate;

   if(strOrderDate.length < 8)
   {
   alert("Order date must be in the format dd/mm/yy");
   FORM1.txtOrderDate.focus();
   return false;
   }
   else
   {
   dayOrderDate = "";
   dayOrderDate = dayOrderDate + strOrderDate.charAt(0);
   dayOrderDate = dayOrderDate + strOrderDate.charAt(1);
   
   monthOrderDate = "";
   monthOrderDate = monthOrderDate + strOrderDate.charAt(3);
   monthOrderDate = monthOrderDate + strOrderDate.charAt(4);
   
   yearOrderDate = ""
   yearOrderDate = yearOrderDate + strOrderDate.charAt(6);
   yearOrderDate = yearOrderDate + strOrderDate.charAt(7);
   yearOrderDate = "20" + yearOrderDate;
   }
   
   if(strCompletionDate.length < 8)
   {
   alert("Deadline date must be in the format dd/mm/yy");
   FORM1.txtCompletionDate.focus();
   return false;
   }
   else
   {
   dayCompletionDate = "";
   dayCompletionDate = dayCompletionDate + strCompletionDate.charAt(0);
   dayCompletionDate = dayCompletionDate + strCompletionDate.charAt(1);
   
   monthCompletionDate = "";
   monthCompletionDate = monthCompletionDate + strCompletionDate.charAt(3);
   monthCompletionDate = monthCompletionDate + strCompletionDate.charAt(4);
   
   yearCompletionDate = ""
   yearCompletionDate = yearCompletionDate + strCompletionDate.charAt(6);
   yearCompletionDate = yearCompletionDate + strCompletionDate.charAt(7);
   yearCompletionDate = "20" + yearCompletionDate;
   }
   
   var OrderDate, CompletionDate, todaysDate;
   todaysDate = new Date();
   //new Date(year, month, day, hours, minutes, seconds, milliseconds)
   CompletionDate = new Date(yearCompletionDate, monthCompletionDate - 1,
dayCompletionDate, 0, 0, 0, 0 );
   OrderDate = new Date(yearOrderDate, monthOrderDate - 1, dayOrderDate, 0,
0, 0, 0 );
   
   if (CompletionDate < OrderDate )
   {
    alert("The deadline: " + CompletionDate + "\n" + "Is less than the
report date: " + OrderDate + "\n" +"Please enter a deadline that is greater
than the report date.");
    FORM1.txtCompletionDate.focus();
	return false;
   }
   
return true;
}

-->
</script>

Cheers

Sam

Sam Clohesy
Project Manager
T: 0208 772 3958
E: samc@e...
W: http://www.etypemedia.co.uk
W: http://www.siteactive.net


-----Original Message-----
From: Gui You [mailto:guiyou01@y...]
Sent: 10 February 2003 15:26
To: ASP Databases
Subject: [asp_databases] Comparing Date display



Hi All,

I have a ASP script that has two input boxes: Start Date , End Date.
Following is my codes:

StartDate = FormatTimeDate(Request.Form("startdate"),2) 

EndDate = FormatTimeDate(Request.Form("enddate"),2)

CurrentDate = FormatTimeDate(Now(),2)

If StartDate > EndDate Then 

Response.write "<script language=javascript>alert(""you entered is Not valid
date."");</script>

Else if EndDate < CurrentDate Then

Response.write "<script language=javascript>alert(""you entered is exceeded
date."");</script>

end if 

end if

= = = = = 

my problem is that the error msg does not display peroperly. So I want to
know how to compare the dates. Thank you for your help in advance.

YoYo



---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

Message #3 by "Peter Foti (PeterF)" <PeterF@S...> on Mon, 10 Feb 2003 10:53:03 -0500
Use the DateDiff function.  You can find more info on this function here:
http://www.devguru.com/Technologies/vbscript/quickref/datediff.html

Regards,
Peter Foti


> -----Original Message-----
> From: Gui You [mailto:guiyou01@y...]
> Sent: Monday, February 10, 2003 10:26 AM
> To: ASP Databases
> Subject: [asp_databases] Comparing Date display
> 
> 
> 
> Hi All,
> 
> I have a ASP script that has two input boxes: Start Date , 
> End Date. Following is my codes:
> 
> StartDate = FormatTimeDate(Request.Form("startdate"),2) 
> 
> EndDate = FormatTimeDate(Request.Form("enddate"),2)
> 
> CurrentDate = FormatTimeDate(Now(),2)
> 
> If StartDate > EndDate Then 
> 
> Response.write "<script language=javascript>alert(""you 
> entered is Not valid date."");</script>
> 
> Else if EndDate < CurrentDate Then
> 
> Response.write "<script language=javascript>alert(""you 
> entered is exceeded date."");</script>
> 
> end if 
> 
> end if
> 
> = = = = = 
> 
> my problem is that the error msg does not display peroperly. 
> So I want to know how to compare the dates. Thank you for 
> your help in advance.
> 
> YoYo
> 
> 
> 
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now
> 
> 

  Return to Index