SHAH NEWAZ
SHAH NEWAZ

Reputation: 11

How to separate date & time from a date time in SQL?

2019-09-05 23:07:16.643 I want to get 2019-09-05 & 23:07:16.643 separately.

Upvotes: 0

Views: 1414

Answers (2)

Himanshu
Himanshu

Reputation: 3970

As by the assumption that database is not known can try to manipulate datetime by splitting it before and after space.

   Select SUBSTR(datetime,1, 
      Instr(datetime, ' ')) as date,
    Substr(datetime, Instr(datetime, ' ')+1, 
      length(datetime)) as time from table

Upvotes: 0

You can see this link Convert datetime in sql and use the conversation format of your preference.

something like this in sql

select convert(varchar, getdate(), 111) as OnlyDate, convert(varchar, getdate(), 8) as OnlyTime

for c#

var date = DateTime.Now.Date; //get only date
var time = DateTime.Now.TimeOfDay; //get only time 

Upvotes: 1

Related Questions