Subtract Two Date Time Values in SQL Server -


i want subtract 2 date time values :

i have start datetime #2015-06-14 23:00:00# end date time #2015-06-15 01:01:00#

i want duration time format hh:mm:ss , update in duration column tried below code but, doesn`t work.

update [zainjta].[dbo].[tbl_justification]   set [justification_event_duration]=convert(datetime,(datediff("n",[justification_from],[justification_to])/60/24),108) 

datediff returns int, dividing 2 other ints going give - int, zero.

try:

convert(datetime,(datediff(s,[justification_from],[justification_to])/60.0/60/24),108) 

(the 60.0 trigger conversion floating point format.)

however, it'd make more sense store number of seconds (integer), , convert when output display.

to display just time, no day/year part, you'll need second conversion:

convert(varchar, convert(datetime,     (datediff(s,[justification_from],[justification_to])/60.0/60/24),108),108) 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -