Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add time datatype column in SQL server

I have a table in sql server 2012,with column named Duration as Time datatype.i want to update this column base on difference of dates, by adding the difference to this duration column.how can I do this in SP.

ID    StartDate               EndDate                 Duration
1     2017-02-27 09:10:35     2017-02-27 09:25:35      00:15
2     2017-02-27 09:26:35   2017-02-27 09:36:35        00:25

Durtion always less than 24 hours.

like image 240
SajidBp Avatar asked Jun 21 '26 18:06

SajidBp


1 Answers

One method is:

update t
    set duration = cast(dateadd(ms, datediff(ms, startdate, enddate), 0) as time);
like image 104
Gordon Linoff Avatar answered Jun 23 '26 09:06

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!