Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I prevent a user from entering data for a future date?

Status
Not open for further replies.

tokuzumi

Programmer
Sep 16, 2002
40
US
I have a text box, that you input a date into (eg: 1/2/2003), and then the user will hit a submit button. If the date is in the future, the page will post a message saying you cannot enter data for a future date.

Here is the code I'm using: The name of the text box is Activity_Date
--------------------
Today = date()
Today = trim(Today)

If Activity_Date > Today then

'redirect the user to the page, with message, saying they need to enter a date that is not in the future.

end if
--------------------

Everything appears to be in line, at least in my head, anyway, but when I run the code, no matter what date I select, past or present, it says that I cannot enter data for a future date. I have run the page in debug, and for both the Activity_Date and Today, the date is in "", so it shouldn't be a formatting problem. I am going to try to mess with JavaScript, and see what that does, but I want to find out what I'm doing wrong with the code above. I"m sure it's something simple. Thanks for any help.
 
Try this:

Today = date()

If cDate(Activity_Date) > Today then

'redirect the user to the page, with message, saying they need to enter a date that is not in the future.

end if
Get the Best Answers! faq333-2924
Happy 2003! [cheers]
mikewolf@tst-us.com
 
I tried that exact bit of code (cdate) right before I read your post, and that just allows any date to go through. I had thought that since the textbox value for the date would be considered as a string, and the date() function is obviously a date, so I tried converting it. I'll mess around with maybe creating another variable for the activity date, using the cdate function. Thanks. Any other ideas?
 
Nevermind, I figured it out. Here is how I did it:

Today = date()
I commented out the "Today = trim(Today)" line

and then, I did this:

If Activity_Date <> &quot;&quot; or not isempty(Activity_Date) then
Activity_Date = cdate(Activity_Date)
end if

then when comparing Today, and Activity_Date, everything went as planned. Thanks for the ideas, mwolf00.
 
Yeah, you'll notice I got rid of the trim(Today) line too. I'm glad you got it.... Get the Best Answers! faq333-2924
Happy 2003! [cheers]
mikewolf@tst-us.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top