SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to get current year from SQL query?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Swati Jain
Posting Yak Master

India
139 Posts

Posted - 10/22/2007 :  10:21:02  Show Profile  Reply with Quote
How to get current year from SQL query?

khtan
In (Som, Ni, Yak)

Singapore
17601 Posts

Posted - 10/22/2007 :  10:25:17  Show Profile  Reply with Quote
year(getdate())


KH
Time is always against us

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22754 Posts

Posted - 10/23/2007 :  02:11:38  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
or

Select datepart(year,getdate())


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30217 Posts

Posted - 10/23/2007 :  02:14:12  Show Profile  Visit SwePeso's Homepage  Reply with Quote
All suggestions above assumes you have the proper datetime set on the sql server where the query is run.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17601 Posts

Posted - 10/23/2007 :  03:49:05  Show Profile  Reply with Quote
Duh !


KH
Time is always against us

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30217 Posts

Posted - 10/23/2007 :  05:10:26  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Hey! Just to be sure...



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Kristen
Test

United Kingdom
22403 Posts

Posted - 10/23/2007 :  05:24:27  Show Profile  Reply with Quote
Time zones, daylight saving (or not), etc. to be considered when using SQL server time ... but also the benefit that its a consistent time for ALL users, whatever time zone THEY are in

Often overlooked is data entered during the 1 hour when the clocks have gone back in the Fall/Autumn ...

Edited by - Kristen on 10/23/2007 05:25:05
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17601 Posts

Posted - 10/23/2007 :  07:08:02  Show Profile  Reply with Quote
OP only wanted the current year, will daylight saving changes occurs at Dec 31 or Jan 1 ?




KH
Time is always against us

Go to Top of Page

Kristen
Test

United Kingdom
22403 Posts

Posted - 10/23/2007 :  07:10:19  Show Profile  Reply with Quote
I was just trying to "talk it up"

Mind you ... if server is operating without daylight savings, in order to NOT have the one-hour-lost problem in the fall, then between 11pm and midnight on 31st December there might be a real problem getting a valid year.
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17601 Posts

Posted - 10/23/2007 :  07:12:09  Show Profile  Reply with Quote
quote:
Originally posted by Kristen

I was just trying to "talk it up"

Mind you ... if server is operating without daylight savings, in order to NOT have the one-hour-lost problem in the fall, then between 11pm and midnight on 31st December there might be a real problem getting a valid year.


Are you pulling my leg ? Sorry, i come from a time zone where daylight saving is totally foreign to me.


KH
Time is always against us

Go to Top of Page

Kristen
Test

United Kingdom
22403 Posts

Posted - 10/23/2007 :  07:16:44  Show Profile  Reply with Quote
Do you not have Summer time then?

In Fall/Autumn the clocks go "back" one hour. This happens at 3am I think, so you get 2:58, 2:59, 2:00, 2:01 ... 2:58, 2:59, 3:00 ...

If you have database synchronisation based on timestamp on records this could obviously cause you to miss some changes.

We therefore set our SQL boxes to NOT adjust for daylight saving time.

Which in turns means that they are an hour different for part of the year. (I can't remember which, but I think they are correct in Summer and one-hour-different in Winter).

So there is a window-of-opportunity within an hour of 31-December-midnight to get the wrong year.

I'm sure this is a viewpoint which is excessively pedantic, but may be useful to be aware of in some circumstances.

Kristen

Edited by - Kristen on 10/23/2007 07:17:38
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000