Convert a day number to the name of the day

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Convert a day number to the name of the day

Post by Pat »

Is there an Access function that can convert a day number (eg 6) to its name (eg Friday)?

User avatar
HansV
Administrator
Posts: 78615
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Convert a day number to the name of the day

Post by HansV »

You can use the WeekdayName function:

WeekdayName(6, False, 1) returns "Friday"

WeekdayName(6, True, 1) returns "Fri"

You can replace 6 with a variable or expression, of course.

Or, if you have a date variable, use Format(datevariable, "dddd") for "Friday" or Format(datevariable, "ddd") for "Fri".

Note: both WeekdayName and Format will use the local language, i.e. on a French-language system you'd get "vendredi" and "ven".
Best wishes,
Hans

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: Convert a day number to the name of the day

Post by Pat »

Thanks Hans, i didn't know about that function, i came up with a convoluted formula which doesn't take into account ther start day of the week:

Format(Date + (iDay - Weekday(Date)), "dddd")

I will use yours.