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 |
|
pavlos
Yak Posting Veteran
59 Posts |
Posted - 2011-12-27 : 21:15:52
|
| Hey all,I have run the following query:select GETDATE()--and it returns(No column name)2011-12-28 13:08:40.350i want to convert the date into 3 seperate columnsYEAR | MONTH | DAY2011 | 12 | 28is it possible? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-12-27 : 21:23:18
|
[code]select datepart(year, getdate()), datepart(month, getdate()), datepart(day, getdate())[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
pavlos
Yak Posting Veteran
59 Posts |
Posted - 2011-12-27 : 21:28:21
|
| Wow thanks,how would I go just subtracting 1 day off the dateis it getdate(day)-1 |
 |
|
|
pavlos
Yak Posting Veteran
59 Posts |
Posted - 2011-12-27 : 21:31:18
|
| select (getdate() - DAY(7)) this works.. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-12-27 : 22:13:58
|
quote: Originally posted by pavlos Wow thanks,how would I go just subtracting 1 day off the dateis it getdate(day)-1
select getdate() - 1orselect dateadd(day, -1, getdate()) KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-12-27 : 22:16:27
|
quote: Originally posted by pavlos select (getdate() - DAY(7)) this works..
this actually subtract 8 days from current day.date value 0 is 1900-01-01date value 7 is 1900-01-08so DAY(7) which is DAY('1900-01-08') gives you the "day" of the input date which is 8day( <date> ) is the same as datepart(day, <date> ) KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|
|
|