Advice on dates (not the lonely hearts ones)

L

Laphan

Hi All

Have a couple of quandaries that I was wondering if you could assist on:

1) Created a page whereby the user selects the day, month and year from 3
separate pop-ups rather than all the rigmarole of checking what kind of date
they enter in 1 text box. My quandary here is that there is going to be a
smart alec (probably a brown noser who wants to take my client away from me)
who'll select something like 31 April 2003 from the pop-ups, which will
obviously make the system blow a gasket as it tries to file this incorrect
date.

Has anybody thought of a good way to trap this without a load of JavaScript
whatsits?

I was thinking of checking the month and if the day was over 30 for month
x,y,z then fix it to 30 before I file it to the DB. Best way?

2) I have setup a system where news messages are given an expiry date so
that when they are older than today's date they aren't displayed on the
site.

My problem is that even though I thought my syntax of:

IF MyDateVar < Now() THEN
don't display it
ELSE
display
END IF

was OK, if MyDateVar is the same date as Now() it's still classing it as
expired even though my test clearly shows that it is testing if it is less
than today (ie, Now).

Bizarre or what??

If you are kind enough to reply, could you please post in the NG rather than
my email address, as I have 'fudged' it to stop bogus MS viruses.

Rgds

Laphan
 
A

Aaron Bertrand - MVP

I was thinking of checking the month and if the day was over 30 for month
x,y,z then fix it to 30 before I file it to the DB. Best way?

NO.

Then you have to deal with February (28 days, and sometimes 29). Use a date
object, and use the VBScript isDate() function once the date has been
submitted to the server. Instead of massaging the data for them and make it
work by picking the closest valid date, return an error message and tell
them to stop being a smart alec. They might even learn something new about
our calendar.
2) I have setup a system where news messages are given an expiry date so
that when they are older than today's date they aren't displayed on the
site.

My problem is that even though I thought my syntax of:

IF MyDateVar < Now() THEN

Are you pulling ALL of the data back from the database, and then looping
through ALL of the data, and checking EVERY single row to make sure it meets
some criteria? You might, maybe, consider putting a WHERE clause on your
SQL statement. Assuming an index on the datetime column, this will make
your database happier, will make your network usage increasingly more
efficient than it will be in the current scheme (since the data, assumedly,
is growing), and will completely eliminate any need to check the data before
displaying it. Only pull data that you *need*... it is a total waste to ask
for the whole year when all you care about is today.
was OK, if MyDateVar is the same date as Now() it's still classing it as
expired even though my test clearly shows that it is testing if it is less
than today (ie, Now).

Bizarre or what??

No, this is not bizarre. I'm assuming MyDateVar is something like
'2003-10-09 04:35:00 PM'. Guess what? Now() is '2003-10-09 06:06:00 PM'...
which is greater? Maybe you meant to use Date() instead of Now().
If you are kind enough to reply, could you please post in the NG rather than
my email address, as I have 'fudged' it to stop bogus MS viruses.

Yep, that's the way peer-to-peer forums work; post here, read here.
 
H

Hannibal

for the smartass:
just use a client-side vbscript check for the date

if not isDate(myDate) then
msgBox "Ur a smartAss!!"
end if

oh, and yeah...

NOW() and Today are not the same :)
Today happened before NOW() hehehhe....
 
L

Laphan

HI Aaron/Hannibal

Many thanks for invaluable advice. As always, all your pointers did the
trick.

Best Regards

Laphan

PS: Aaron, I knew you'd crack that special paging thing. Just as a matter
of interest is it possible to create the same thing in Access or is it too
complex a procedure??




for the smartass:
just use a client-side vbscript check for the date

if not isDate(myDate) then
msgBox "Ur a smartAss!!"
end if

oh, and yeah...

NOW() and Today are not the same :)
Today happened before NOW() hehehhe....
 
A

Aaron Bertrand - MVP

PS: Aaron, I knew you'd crack that special paging thing. Just as a matter
of interest is it possible to create the same thing in Access or is it too
complex a procedure??

It uses temp tables, so no, I don't think it would be trivial to duplicate
in Access. You might consider using MSDE.

However, having said that, you could certainly pull all the rows into a
disconnected recordset and organize them that way in ASP. Won't be quite as
efficient or elegant, but it could be done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top