Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert date and time in SQL Server

I have the following columns in a table:

Signed_In_Date             Signed_Out_Time
11/1/2005 12:00:00 am      11/1/2005 10:27:00PM

I would like to convert them to the following output:

Signed_In_Date      Signed_Out_Time
11/1/2005           10:27:00PM

Is there a function or conversion code in SQL Server that would do it?

like image 747
joe Avatar asked Feb 21 '23 02:02

joe


1 Answers

Assuming that the columns you're referring to are DATETIME columns, I would use the code below:

Date Only

SELECT CONVERT(VARCHAR(10), GETDATE(), 101)

Time Only

SELECT LTRIM(RIGHT(CONVERT(VARCHAR(20), GETDATE(), 100), 7))

You can see the queries in action / play with them here.

like image 88
James Hill Avatar answered Feb 24 '23 05:02

James Hill