DatePart Function

  • Thread starter Thread starter Adam
  • Start date Start date
A

Adam

I have a field in a table that holds the "day" of the week
(i.e. Monday,Tues., etc).

I want to query the table for what ever "today" is. So if
today was Tuesday I would want all those that
have "Tuesday."

Currently I'm using the DatePart Function but it is
returning all the days of the week in my record set which
is ok except it is returning them all in a number value.
BUt how do I set criteria to choose only the current day
of the week or how do i convert the serial number value
that is returned to a text value of "Monday" "Tuesday"
etc.???
 
When you say that the field holds the day of the week, what do you mean? Is
it a Date field, or is it a text field that contains the name of the day or
is it numeric field that contains the weekday number?

If it's a date, then you can add two computed fields to your query: one to
return the weekday number (DatePart("d", MyDate), or Weekday(MyDate)), and
another to return the name of the weekday (Format(MyDate, "ddd") to get Mon,
Tue, Wed, or Format(MyDate, "dddd") to get Monday, Tuesday, Wednesday)

Put your criteria against the first one (i.e.: Weekday(MyDate) =
Weekday(Date())), but display the second one.
 
Thanks Doug, it is actually a text field with the weekday
name in it (mon, tues, wed, etc.).
It comes from a table with just one other field in it (the
weekday id field id's run 1 thru 7.

If it helps what I'm basically trying to do is have the
query pull those records who's day of week value (in text)
matches what ever day of week it currently is today..?
 
Your WHERE clause needs to be something like

WHERE MyDateField = Format(Date(), "dddd")
 
Back
Top