Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mark1504
Posting Yak Master
103 Posts |
Posted - 2004-10-12 : 08:38:14
|
| OK, even I know that:SELECT DATENAME(dw,GETDATE()) will return Tuesday (at time of writing ;-)BUT how can I return the name of the day from a table where I store the day of the week as a number (i.e. 1 represents Monday)? I'm sure it must be easy but I just can't find it.ThanksMark |
|
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2004-10-12 : 08:45:54
|
| There's probably a more elegant way of doing it, but you could pick a date that you know to be a Sunday and use DATEADD in conjunction with DATENAME, i.e.SELECT DATENAME(dw, DATEADD(day, dn.DayNum, '10/Oct/2004'))FROM DayNumbersTable AS dnMark |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-12 : 08:52:56
|
select datename(dw, 0) -- this return monday for meselect datename(dw, 1) -- this return tuesday for me...Go with the flow & have fun! Else fight the flow |
 |
|
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2004-10-12 : 09:13:19
|
| I guess that's because 1 Jan 1900 happened to be a MondayMark |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-12 : 09:20:33
|
well it acctually doesnt matter you can still use it Go with the flow & have fun! Else fight the flow |
 |
|
|
mark1504
Posting Yak Master
103 Posts |
Posted - 2004-10-12 : 10:38:52
|
| Ha!I'd actually noticed that 1 Jan 1900 effect while I was trying things. It's certainly an easy method.I guess it'll be a reliable enough even though I'd prefer Monday to be 1 and not 0. Many thanks |
 |
|
|
|
|
|