| Author |
Topic |
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-07-02 : 01:54:08
|
| Hi, i was sleepy and just now i saw an OP ask retrieve week...i wanna ask is it posible to get whole year date from just 4 digit? i google it but can't find any infor that can helpAMITOFO+AMEN+YA ALLAH Hope the query works |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-02 : 01:55:09
|
datepart(year, thedate)year(thedate) KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-07-02 : 01:58:19
|
| hm..i mean that is...example i key in 1900 into a function...it will show the whole year date from 01/01/00-31/12/00(365 rows affected)AMITOFO+AMEN+YA ALLAH Hope the query works |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-02 : 02:02:17
|
one quick way, use this F_TABLE_DATEor number table F_TABLE_NUMBER_RANGE to generate the date KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-07-02 : 02:08:55
|
| wow since when you touch sql...knows so much of thing!AMITOFO+AMEN+YA ALLAH Hope the query works |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-07-02 : 03:07:29
|
If you just want the starting date and the ending date,DECLARE @theYear SMALLINTSET @theYear = 2007SELECT DATEADD(YEAR, @theYear - 1900, 0), DATEADD(YEAR, @theYear - 1899, -1) Microsoft SQL Server MVPN 56°04'39.26"E 12°55'05.63" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-02 : 03:10:54
|
| declare @year intset @year=2000select dateadd(year,@year-1900,dateadd(day,number-1,0)) from (select row_number () over (order by name) as number from sysobjects) as twhere year(dateadd(year,@year-1900,dateadd(day,number-1,0)) )=@yearMadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-02 : 03:11:04
|
quote: Originally posted by waterduck wow since when you touch sql...knows so much of thing!AMITOFO+AMEN+YA ALLAH Hope the query works
Actually not that long compare to others. I only started "touching" MS SQL Server since 2003. Stick around SQLTeam. You will learn much more from anywhere else. KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-07-02 : 03:24:02
|
6 Years!!! i must learn all urs knowlegde within 1 year AMITOFO+AMEN+YA ALLAH Hope the query works |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-02 : 03:29:18
|
quote: Originally posted by waterduck 6 Years!!! i must learn all urs knowlegde within 1 year AMITOFO+AMEN+YA ALLAH Hope the query works
OK. I will do a database backup and FTP to you  KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-07-02 : 03:30:58
|
| i wonder peso get his salary raise for his mvp?AMITOFO+AMEN+YA ALLAH Hope the query works |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-02 : 03:36:39
|
quote: Originally posted by waterduck i wonder peso get his salary raise for his mvp?AMITOFO+AMEN+YA ALLAH Hope the query works
It depends MadhivananFailing to plan is Planning to fail |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-07-02 : 03:38:10
|
haha..so he planing to treat us?if not...i think....rollback AMITOFO+AMEN+YA ALLAH Hope the query works |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-07-02 : 03:38:15
|
Madhi, I am missing the leapday of February 29thdeclare @year intset @year = 1904select distinct dateadd(year, @year - 1904, number) from ( select row_number() over (order by name) + 1459 as number from sysobjects ) as twhere year(dateadd(year, @year - 1904, number)) = @year Microsoft SQL Server MVPN 56°04'39.26"E 12°55'05.63" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-02 : 03:50:14
|
Yes. Thanks MadhivananFailing to plan is Planning to fail |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-07-02 : 03:53:16
|
| means what?AMITOFO+AMEN+YA ALLAH Hope the query works |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-02 : 03:58:52
|
quote: Originally posted by waterduck means what?AMITOFO+AMEN+YA ALLAH Hope the query works
run both query (Madhi & Peso), set the same year @year = 1904 , compare and see the different ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-07-02 : 04:29:01
|
| >"< i can't understand why madhi query left that dayAMITOFO+AMEN+YA ALLAH Hope the query works |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-02 : 04:33:14
|
because his based year is 1900. 1900 is not a leap year. For the month of Feb 1900, there isn't a Feb 29.so the following will not have a Feb 29 for the selected year (@year)dateadd(year, @year-1900, dateadd(day, number - 1, 0)) the section in bold is basically adding number to date 0. Date 0 is 1900-01-01 KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-07-02 : 04:35:30
|
| dateadd(year, @year-1900, dateadd(day, number - 1, 0))Bold = isn't here convert back to 1904?AMITOFO+AMEN+YA ALLAH Hope the query works |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-02 : 04:39:35
|
quote: Originally posted by waterduck dateadd(year, @year-1900, dateadd(day, number - 1, 0))Bold = isn't here convert back to 1904?AMITOFO+AMEN+YA ALLAH Hope the query works
That's the idea. If the required date is 1904, @year = 19041904 - 1900 = 4. So you add 4 years to the date in blue KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Next Page
|