Calculating diffrence in minutes using datetiff function

  • Hello,

    I have a problem where i want to get the diffrence in minutes between two times, my datatype is TIME, i have also used the function below

    ABS(DATEDIFF (MINUTE, cd.StartTime , p.StartTime)) AS MinuteDiff.

    the problem is, where i have a cd.startime of 19:00:00 and a p.startime of 00:00:00, it returns 1140 minutes (19hrs) as the minute difference, how can i get the minute difference appropriately as (300 minutes=5hrs) this is the appropriate difference between 19:00 and 00:00(being 12 am).

    I learn from the footprints of giants......

  • JALLYKAMOZE (8/30/2016)


    Hello,

    I have a problem where i want to get the diffrence in minutes between two times, my datatype is TIME, i have also used the function below

    ABS(DATEDIFF (MINUTE, cd.StartTime , p.StartTime)) AS MinuteDiff.

    the problem is, where i have a cd.startime of 19:00:00 and a p.startime of 00:00:00, it returns 1140 minutes (19hrs) as the minute difference, how can i get the minute difference appropriately as (300 minutes=5hrs) this is the appropriate difference between 19:00 and 00:00(being 12 am).

    But the difference between 19:00:00 and 00:00:00 IS 19 hours and it is also 5 hours. It is all based on the direction of time you want to figure. But for SQL Server's math, you would have to use the full datetime if you want it to realize 00:00:00 is Midnight of the next day.

    SELECT DATEDIFF (MINUTE, '2016-08-29 19:00:00' , '2016-08-30 00:00:00')

    -SQLBill

  • edit deleted...not a good solution sorry !

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • PLEASE DO NOT POST A SINGLE QUESTION IN MULTIPLE FORUMS ANY MORE.

    MOST OF US CHECK THROUGH ALL OF THE FORUMS.

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply