Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 3rd, 2005, 11:26 AM
Authorized User
 
Join Date: Jul 2003
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I compare 2 dates?

Is anyone able to help me with this (supposedly simple) problem:

I have 2 text boxes on a page, one called stopdate and one called currentdate and a submit button.

I can enter in a date (format dd/mm/yyyy) into stopdate, and in currentdate I have <%=date%>.

When I click on the submit button I have a process page which has the following code on it:

<%
Dim stopdate
stopdate = ""
If (Request("stopdate") <> "") then stopdate = Request("stopdate")

Dim currentdate
currentdate = ""
If (Request("currentdate") <> "") then currentdate = Request("currentdate")

if (stopdate > currentdate) then response.write "this is in the future."

%>

So, i enter in 05/05/2005 into stopdate (with current date being 03/05/2005) and the message pops up as expected. However, if i enter in 05/04/2005 I get the same message, even though it's in the past!

What am i doing wrong?

Thanks in advance

Lucy xx



 
Old May 3rd, 2005, 07:24 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Hello Lucy

Sound like your machine date format is set to American date which is mm/dd/yyyy:

When you enter 05/05/2005, it is the 5th of the 5th month (no problem there). Your "current date being the 03/05/2005" I believe your machine is saying it's actually the 5th of the 3rd month - this of course is in the future (as is the 3rd of the 5th month) therefore you get your "this is in the future" alert.

However:
When you enter "05/04/2005" instead of it being the 5th of the 4th month - I believe it's being interpreted as the 4th of the 5th month. Of course the 4th of the 5th month is after your current date which as I said is being interpreted as the 5th of the third month.

Hope that didnt sound to confusing. It makes very good sense, I have struck this problem myself. Living in Australia we strictly use the dd/mm/yyyy format. You may say all your regional settings are showing the dd/mm/yyyy format, yes myn did to. IIS v < 6.0 does strange things with date formats. Changing a registry setting will solve your problems. This post has a massive amount of very useful info on this topic, including US and AU date functions and the solution. It is a long collection of posts but well worth the read if you are in a prt of the world that uses dd/mm/yyyy formats.

The solution is in the last post, it is:
-----------------------------------
It did not work for me, what did:
HKEY_USERS\.DEFAULT\Control Panel\International\Locale = 00000C09
That value will give you dd/mm/yyy
-----------------------------------

Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to compare two dates lakshmi_annayappa Javascript 1 September 3rd, 2007 08:52 AM
How to use the datediff function to compare dates cesemj VB How-To 0 June 9th, 2006 04:03 PM
Compare dates langer123 Classic ASP Basics 2 April 16th, 2005 08:57 AM
Compare dates [problem]... Varg_88 VB Databases Basics 3 August 20th, 2004 09:55 AM
Compare Dates in JS apd8x Javascript 4 June 16th, 2003 08:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.