Plz need help in time manipulation.

  • Hi guys,

    I have used DateDiff build-in function :exclamation:of sql server to get time difference in HH but facing some problem. I don't know why it's happening so:

    SELECT DATEDIFF(HH,CAST('15:58:00.0000000' as TIME),CAST('16:02:00.0000000' as TIME))

    Returns: 1 Hours

    the difference between these two time is around 4 min so, query should return 0 hours but it's returning 1. I don't know why?

    So, please anybody come-up with some explanation why is this happening.

    Regards,

    Jangid

  • Try

    SELECT (DATEDIFF(SECOND,CAST('15:03:00.0000000' as TIME),CAST('16:02:00.0000000' as TIME))/3600)

  • Here is a good reference on how DATEDIFF works: http://www.sqlteam.com/article/datediff-function-demystified.

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

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