Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Check for valid date range
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic ClosedCheck for valid date range

 Post Reply Post Reply
Author
Awangku View Drop Down
Groupie
Groupie


Joined: 15 November 2001
Location: Malaysia
Status: Offline
Points: 70
Direct Link To This Post Topic: Check for valid date range
    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.

Back to Top
ultramods View Drop Down
Groupie
Groupie
Avatar

Joined: 08 January 2003
Location: Scotland
Status: Offline
Points: 146
Direct Link To This Post 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"))
%>

Back to Top
Awangku View Drop Down
Groupie
Groupie


Joined: 15 November 2001
Location: Malaysia
Status: Offline
Points: 70
Direct Link To This Post 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?

 

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Direct Link To This Post 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.
Back to Top
Awangku View Drop Down
Groupie
Groupie


Joined: 15 November 2001
Location: Malaysia
Status: Offline
Points: 70
Direct Link To This Post 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.

 



Edited by Awangku
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Direct Link To This Post 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);
}

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.