question

SAQ-5842 avatar image
0 Votes"
SAQ-5842 asked MelissaMa-msft answered

Date Function

Create a field in Table Colum:- tbl_inst_install_date Data Type -----varchar(50) Date 03/02/2016

No, I want to Convert this Colum Date from 03/02/2016 to 2016 (dd/mm/yyyy) To (YYYY)

Kindly Advise us

sql-server-generalsql-server-transact-sql
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MelissaMa-msft avatar image
0 Votes"
MelissaMa-msft answered

Hi @SAQ-5842,

Welcome to Microsoft Q&A!

Please refer below:

 select year(cast(yourcolumn as date)) from yourtable

 select format(cast(yourcolumn as date),'yyyy') from yourtable

 select  right(yourcolumn,4) from yourtable

Best regards,
Melissa


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.