Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

concat year from datetime

Posted on 2014-12-08
2
Medium Priority
?
94 Views
Last Modified: 2014-12-30
hI,
i HAVE UPDATE_DATE AS datetime,
i want to concat the year from that date

doing

select year(UPDATE_DATE) from x  not liking it
0
Comment
Question by:sam2929
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 total points
ID: 40487314
Define 'not liking it', preferably with whatever error message is returned when the above is executed.

The syntax select year(datetime_column_name) from table_name is correct, as the below code returns '2014' on my SQL 2008 box.
SELECT YEAR(GETDATE())

Open in new window

0
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 40487405
If you're trying to concatenate it, be sure to cast it to varchar as well:

select cast(year(UPDATE_DATE) as varchar(4)) + ...
from x
...
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question