| Author |
Topic |
|
Trininole
Yak Posting Veteran
83 Posts |
Posted - 2010-05-12 : 14:22:03
|
| how to convert a date to a day? For example the date, "2010-11-26" is on a Friday? How can i convert any date to a day in sql? What is the syntax for it?Roger DeFour |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-12 : 14:29:20
|
select datename(dw, getdate()) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Trininole
Yak Posting Veteran
83 Posts |
Posted - 2010-05-12 : 14:37:54
|
| But that syntax is going to give me today's day which is wednesday, but how would i place a date in there in order to get back the right day besides today??Roger DeFour |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-12 : 14:42:53
|
Do you have an example so I can know where your date will come from? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Trininole
Yak Posting Veteran
83 Posts |
Posted - 2010-05-12 : 14:45:02
|
| ok for example, what would the syntax be if i just put in any date in the format like this for example, "2010-12-25"? That date is on saturday, what would the syntax be to get the answer saturday by using that date?Roger DeFour |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-12 : 14:46:55
|
select datename(dw, '20101225') No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-12 : 14:48:06
|
Orselect datename(dw, replace('2010-12-25','-','')) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-12 : 14:53:49
|
Orselect datename(dw, convert(datetime,'2010-12-25',126)) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Trininole
Yak Posting Veteran
83 Posts |
Posted - 2010-05-12 : 14:59:49
|
| Thank youRoger DeFour |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-12 : 15:01:53
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Trininole
Yak Posting Veteran
83 Posts |
Posted - 2010-05-12 : 15:14:00
|
| How would i write the syntax if today's date was on a thursday and today's date is not located in the table called "holiday", how would i make it write "yes" if today's date is not in the table and "no" if it is in the table?Roger DeFour |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-12 : 15:28:44
|
something like this:set nocount ondeclare @holiday table (name_of_day varchar(30))insert @holidayselect 'Monday' union allselect 'Tuesday' union allselect 'Wednesday' union allselect 'Friday'if exists(select * from @holiday where name_of_day = datename(dw, getdate()))begin print datename(dw, getdate()) + ' is in table'endelsebegin print datename(dw, getdate()) + ' is not in table'end No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-12 : 15:30:04
|
You can replace @holiday by the name of your holiday table.@holiday is only created and filled to have testdata. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-05-13 : 05:09:30
|
quote: Originally posted by webfred select datename(dw, '20101225') No, you're never too old to Yak'n'Roll if you're too young to die.
Just for clarity useselect datename(weekday, '20101225')MadhivananFailing to plan is Planning to fail |
 |
|
|
kashyapsid
Yak Posting Veteran
78 Posts |
Posted - 2010-05-13 : 05:38:27
|
| yes this worksKaShYaP |
 |
|
|
|