Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server: How to concatenate string constant with date?

select packageid,status+' Date : '+UpdatedOn from [Shipment_Package] 

The below error is appeared when executing the above code in sql server. The type of UpdatedOn is DateTime and status is a varchar. We wanted to concatenate the status, Date and UpdatedOn.

error:

Conversion failed when converting date and/or time from character string.

like image 827
user2901979 Avatar asked Oct 23 '13 11:10

user2901979


1 Answers

Convert Datetime column into varchar for sql Server you can use below code

select packageid,status+' Date : '+CONVERT(VARCHAR,UpdatedOn,120) from [Shipment_Package] 

120 code will convert your date into this format : 2020-06-12 15:09:00 other format you can use from this link

like image 186
Vijay Maurya Avatar answered Nov 09 '22 01:11

Vijay Maurya