p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Basics (http://p2p.wrox.com/forumdisplay.php?f=61)
-   -   Results based on Date (http://p2p.wrox.com/showthread.php?t=2715)

hcweb August 12th, 2003 02:08 PM

Results based on Date
 
I know this has been covered a million times already, and there's already on topic here that covers this but I can't find it.

I want to query a database. After I get my data, I would like to display based on day of the week.

Something along the lines of :

If dtNow = Now() Then
strWhatever = "red"
etc.

My apologies, but I'm not sure exactly how to explain what I'm looking for. If anyone could help, or point me to the original topic, I'll gladly hand over one of my co-workers... :D

Thanks

Imar August 12th, 2003 02:28 PM

Hi there,

You'll need to take a look at the Weekday method which you can find in the Windows Script section of the MSDN:

The Weekday method returns a 1 based number for the current day of the week, starting at 1 for a Sunday by default.

So, this should work:

Code:

If Weekday(dtNow) = Weekday(Now()) Then
str.... etc
End If

Or, when you need multiple days, use a Select Case statement:

Select Case Weekday(dtNow)
Case 1 ' Sunday
...
Case 2 ' Monday
etc etc
End Select

or define constants for the weekdays if you need them more often, to improve the readability of the code:

Code:

Dim vbSunday
Dim vbMonday
...
vbSunday = 1
vbMonday = 2
...
Select Case Weekday(dtNow)
Case vbSunday
...
Case vbMonday
etc etc
End Select

Hope this helps,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.


All times are GMT -4. The time now is 05:19 AM.

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