sql - Time difference in minutes between two times -
been struggling difference in minutes between 2 times. 1 time comes field of data type time in sql server. other value string added sql query. i'm running in ssrs 2008 r2 looks this:
datediff(mi, convert(time, '23:59:59'), _travel.start_time) time_difference
i error: conversion failed when converting date and/or time character string
i've tried casting '23:59:59' time type 'as time' similar error. have tried declaring variable ssrs won't allow it. try give similar error. time 23:59:59 same, _travel.start_time whatever in field in db. output _travel.start_time in format 00:00:00
any ideas how can difference in minutes between 23:59:59 , db value? ta
added:
can't believe it. _travel.start_time varchar not time. have tried
datediff(convert(time, '23:59:59'), convert(time, _travel.start_time))
but still getting same error. however, have noticed there nulls/empty fields in _travel.start_time field
i see no issue have, unless ssrs
issue or _travel.start_time
not of type time
.
see this: sql fiddle
sample sql:
-- sample trimming time portion off datetime select datediff(mi, convert(time, '23:59:59'), ltrim(right(convert(varchar(20), getdate(), 100), 7))) time_difference -- sample time conversion of datetime select datediff(mi, convert(time, '23:59:59'), convert(time, getdate())) time_difference
in addition, have tried converting db value:
select datediff(mi, convert(time, '23:59:59'), convert(time, _travel.start_time)) time_difference
Comments
Post a Comment