What the hell is wrong with my hour comparison?

  • datediff returns the difference between two datetime values.

    It seems to me the timezone table contains just hours (no dates!) and that's why you won't get the expected results.

    In order to convince yourself, just run the statement select datediff(hour, getdate()-1, getdate()) [you should get 24].

  • Ok, I had the same argument though.  I told my boss that there are no dates.  But we're not looking at the date portion....there are indeeed valid times if you see...

  • 1899-12-30 20:00:00.000 is 8pm

    we have other values like 1899-12-30 21:00:00.000 in that column

  • calldatetime however have valid dates, example 2006-04-07 09:06:52.000

    where

    calldatetime > getdate()-2

    so this part is fine, nothing to worry about there, that's not what I'm working on..I'm working on the time portion, the calldatetime which is 5 minutes after stop1's time at the same hour

    example

    calldatetime                    stop1

    2006-04-07 09:06:52.000 1899-12-30 21:00:00.000

    2006-04-06 15:39:43.000 1899-12-30 21:00:00.000

    2006-04-06 18:10:18.000 1899-12-30 21:00:00.000

    2006-04-06 18:10:51.000 1899-12-30 21:00:00.000

    2006-04-06 20:35:39.000 1899-12-30 21:00:00.000

    2006-04-06 20:50:24.000 1899-12-30 21:00:00.000

    2006-04-06 15:32:04.000 1899-12-30 20:00:00.000

    2006-04-06 17:07:38.000 1899-12-30 20:00:00.000

    2006-04-06 17:11:56.000 1899-12-30 20:00:00.000

    2006-04-06 14:56:00.000 1899-12-30 20:00:00.000

    for the check whether calldatetime is 5 minutes more than stop1, we're only looking at the time portion anyway so what is your concern about the dates...who cares if they are not valid, we are not checking against the dates, just the time portion of stop1 and only the date portion is not really something to be concerned about.

     

  • select datediff( hour, '1899-12-30 20:00:00.000','2006-04-05 20:14:19.000')

    Returns: 931488

    The number of hours between the two dates. That, is why the query you posted returns 0 records when you used datediff(hour, tz.stop1, h.calldatetime) = 0

    if you need to check time parts only Make the Day the same and then use datediff with the hours

    Like

       datediff( hour, '1900-01-01 ' + convert(varchar(12),tz.stop1,114), '1900-01-01 ' + convert(varchar(12),h.calldatetime,114)

    HTH

     

     


    * Noel

  • Would substring be allot slower then datdiff?

    e.g.

    substring(date1,12,2) = substring(date2,12,2)

    I am assuming that we are trying to find rows in one table that are within the same hour as the other table. e.g. 10:15 same as 10:00

    Dave

    Trainmark.com IT Training B2B Marketplace
    (Jobs for IT Instructors)

Viewing 6 posts - 1 through 7 (of 7 total)

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