Click here to Skip to main content
15,919,121 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone

I have a problem with getting the year our of a datetimeoffset field.
I would like to Group a bunch of records by year but whenever i try to get the year out i recieve en error from the SQL server.

My code is as follows

Select YEAR[Posting Date]
From [Cust. Ledger Entry]

If i remove the YEAR it Works fine and i get 11.000 rows with date stamp like this format:
2013-04-29 00:00:00.0000000 +00:00

Why is this not working for me??
Posted
Comments
ZurdoDev 3-Feb-16 8:04am    
What's the error? That will tell you why it isn't working.

But if what you typed is exact then you have a syntax problem.

Should be YEAR([Posting Date])
Kristian_dk 3-Feb-16 9:26am    
Thank for helping out Ryan - your solution was actually correct :-)

1 solution

In SQL brackets used to enclose object (column, table) names that contains keywords to make interpretation easier...
However YEAR[^] is a function and should be used with parentheses...
SQL
Select YEAR([Posting Date])
From [Cust. Ledger Entry]
 
Share this answer
 
Comments
Kristian_dk 3-Feb-16 9:26am    
This helped :-) Thanks a lot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900