Print Page | Close Window

Check for valid date range

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Web Design Discussion
Forum Description: Discussion on web design and development subjects.
URL: https://forums.webwiz.net/forum_posts.asp?TID=4233
Printed Date: 29 March 2026 at 4:21am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Check for valid date range
Posted By: Awangku
Subject: Check for valid date range
Date Posted: 14 July 2003 at 4:40am

I use a form to collect two dates (DateFrom & DateTo). When the form is submitted, it will call up a function that will check whether the date range is valid or not. If DateFrom is greater than DateTo, the range is not valid and the function will produce an error message.

Anybody can help me with that? My dates are using dd-mm-yyyy format.




Replies:
Posted By: ultramods
Date Posted: 14 July 2003 at 5:05am

You could try using this:

<%
OPTION EXPLICIT

FUNCTION dateValidate(date1, date2)

 Dim dateDifference, dateError

 dateDifference = DateDiff("d", date1, date2)

 IF dateDifference < 0 THEN
  dateError = "yes"
 END IF

 dateValidate = dateError

END FUNCTION

response.write(dateValidate("10/04/2000", "09/03/1999"))
%>



Posted By: Awangku
Date Posted: 14 July 2003 at 7:03pm

Can we actually write a FUNCTION using ASP? All this while I've been using JavaScript.

Can I use onSubmit to call up that function?

 



Posted By: michael
Date Posted: 14 July 2003 at 8:22pm
asp functions are server side and onsubmit is done clientside so you cannot do it without reloading the page.

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Awangku
Date Posted: 15 July 2003 at 3:53am

Tell me what's wrong with this script:

<script language="JavaScript">

function doDateCheck() {
     var fromDate = document.frmXX.AppDateFrom.value
     var toDate = document.frmXX.AppDateTo.value

     if (Date.parse(fromDate) > Date.parse(toDate)) {
          alert ("INVALID DATE RANGE !");
          return false;
     }
     return true;
}

</script>

What I'm trying to do is grab two dates from the form frmXX when it's submitted (onSubmit) and check that the range is valid. Somehow I can't get that thing to work.

 



Posted By: michael
Date Posted: 15 July 2003 at 9:31am

Here's a function I got to compare dates. It has the advantage that you can customize your error message depending on how the date has been entered.


The function returns the following values:

        -1 - if date1 < date2
         0 - if date1 = date2
         1 - if date1 > date2

function compareDate(date1,date2)
{
   var aDate = new Date(date1);
   var bDate = new Date(date2);

   if ( aDate.getTime() == bDate.getTime() )
      return 0;

   return (aDate.getTime() < bDate.getTime() ? -1 : 1);
}



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net