WeekdayName in Query

Results 1 to 3 of 3

Thread: WeekdayName in Query

  1. #1
    Tic3 Guest

    Default WeekdayName in Query

    Hi. I have a database of regularly scheduled events. One field is the weekday that the event falls on (eg. Monday, Tuesday, Wednesday, etc.)<BR><BR>I want to be able to use the current system date to search that weekday field for the current day&#039s events. For example, when someone visits the page, I would like to display something like this:<BR><BR>Hello. Today is Monday, September 25, 2000. Today&#039s events are:<BR>11:00 AM Event1 EventDescription<BR>2:00 PM Event2 EventDescription<BR><BR>Etc.<BR><BR>I have tried several bits of code, but nothing seems to work. Example:<BR><BR>Dim TDay<BR>TDay = WeekdayName (Day(Date))<BR>("SELECT * FROM events WHERE day = #" & TDay & "#")<BR><BR>I get an error message similar to: Expected string #Monday#<BR><BR>I&#039ve also tried using DatePart:<BR><BR>Dim TDay = DatePart ("w"(Date())<BR><BR>Same results...various error messages.<BR><BR>Can anyone help me with this? I&#039ve spent hours of trial and error on what should be a simple database query and have gotten nowhere. I do know that I have a good connection with the database, since the query ("SELECT * FROM events") returns all records.<BR><BR>Thanks for any help<BR><BR>tic3@rica.net

  2. #2
    Join Date
    Dec 1969

    Default RE: WeekdayName in Query

    Try:<BR><BR>Dim sDBQ<BR>sDBQ = """"<BR>("SELECT * FROM events WHERE day = " & sDBQ & TDay & sDBQ)

  3. #3
    Join Date
    Dec 1969

    Default Couple of problems

    First, weekdayname(day(date)) is incorrect, since day(date) will return a number from 1 to 31 (depending on the month). You should use, instead:<BR><BR> tday = weekdayname(weekday(date))<BR><BR>Second, you would not pass a weekday name (which is a string value) surrounded by the octothorpe. That is reserved for DATE values only.<BR><BR>If the value in your database is truly a day name (which is bad design, by the way), then you should use something more like this:<BR><BR>("select * from events where day=&#039" & tDay & "&#039")<BR><BR>If your "day" database field is actually a tiny integer (which it should be), then you would use:<BR><BR>("select * from events where day=" & weekday(date))<BR><BR><BR>Hope this helps!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts