Advice on dates (not the lonely hearts ones) | | |
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 | | | | re: Advice on dates (not the lonely hearts ones)
> I was thinking of checking the month and if the day was over 30 for month[color=blue]
> x,y,z then fix it to 30 before I file it to the DB. Best way?[/color]
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.
[color=blue]
> 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[/color]
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.
[color=blue]
> 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??[/color]
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().
[color=blue]
> If you are kind enough to reply, could you please post in the NG rather[/color]
than[color=blue]
> my email address, as I have 'fudged' it to stop bogus MS viruses.[/color]
Yep, that's the way peer-to-peer forums work; post here, read here. | | | | re: Advice on dates (not the lonely hearts ones)
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....
"Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
news:OcBooHrjDHA.360@TK2MSFTNGP12.phx.gbl...[color=blue][color=green]
> > I was thinking of checking the month and if the day was over 30 for[/color][/color]
month[color=blue][color=green]
> > x,y,z then fix it to 30 before I file it to the DB. Best way?[/color]
>
> NO.
>
> Then you have to deal with February (28 days, and sometimes 29). Use a[/color]
date[color=blue]
> 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[/color]
it[color=blue]
> 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[/color]
about[color=blue]
> our calendar.
>[color=green]
> > 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[/color]
>
> 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[/color]
meets[color=blue]
> 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,[/color]
assumedly,[color=blue]
> is growing), and will completely eliminate any need to check the data[/color]
before[color=blue]
> displaying it. Only pull data that you *need*... it is a total waste to[/color]
ask[color=blue]
> for the whole year when all you care about is today.
>[color=green]
> > 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[/color][/color]
less[color=blue][color=green]
> > than today (ie, Now).
> >
> > Bizarre or what??[/color]
>
> 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[/color]
PM'...[color=blue]
> which is greater? Maybe you meant to use Date() instead of Now().
>[color=green]
> > If you are kind enough to reply, could you please post in the NG rather[/color]
> than[color=green]
> > my email address, as I have 'fudged' it to stop bogus MS viruses.[/color]
>
> Yep, that's the way peer-to-peer forums work; post here, read here.
>
>[/color] | | | | re: Advice on dates (not the lonely hearts ones)
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??
Hannibal <Dominique@webadstudio.com> wrote in message
news:#KeJGUxjDHA.2312@TK2MSFTNGP12.phx.gbl...
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....
"Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
news:OcBooHrjDHA.360@TK2MSFTNGP12.phx.gbl...[color=blue][color=green]
> > I was thinking of checking the month and if the day was over 30 for[/color][/color]
month[color=blue][color=green]
> > x,y,z then fix it to 30 before I file it to the DB. Best way?[/color]
>
> NO.
>
> Then you have to deal with February (28 days, and sometimes 29). Use a[/color]
date[color=blue]
> 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[/color]
it[color=blue]
> 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[/color]
about[color=blue]
> our calendar.
>[color=green]
> > 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[/color]
>
> 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[/color]
meets[color=blue]
> 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,[/color]
assumedly,[color=blue]
> is growing), and will completely eliminate any need to check the data[/color]
before[color=blue]
> displaying it. Only pull data that you *need*... it is a total waste to[/color]
ask[color=blue]
> for the whole year when all you care about is today.
>[color=green]
> > 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[/color][/color]
less[color=blue][color=green]
> > than today (ie, Now).
> >
> > Bizarre or what??[/color]
>
> 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[/color]
PM'...[color=blue]
> which is greater? Maybe you meant to use Date() instead of Now().
>[color=green]
> > If you are kind enough to reply, could you please post in the NG rather[/color]
> than[color=green]
> > my email address, as I have 'fudged' it to stop bogus MS viruses.[/color]
>
> Yep, that's the way peer-to-peer forums work; post here, read here.
>
>[/color] | | | | re: Advice on dates (not the lonely hearts ones)
> PS: Aaron, I knew you'd crack that special paging thing. Just as a matter[color=blue]
> of interest is it possible to create the same thing in Access or is it too
> complex a procedure??[/color]
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. |  | Similar ASP / Active Server Pages bytes | | | Forums
Visit our community forums for general discussions and latest on Bytes
/bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 229,155 network members.
|