Comparing datetime

  • Happy holidays!

    Ok, I have a question that seems basic, but I am having major issues. I need to compare the following date/times. Basically I need to select from a table where the date range is between '12/15/2013' and '12/21/2013' and time is BETWEEN 5:00PM and 8:00AM. I cannot seem to get this working.

    Here is what I have... INTERVALSTART is in the following format (datetime): '2013-12-15 18:30:00.000'.

    Any help is greatly appreciated.

    SELECTsum(abncalls), INTERVALSTART

    FROMoadb.hCMSSkill

    WHERE INTERVALSTART >= '12/15/2013 17:00:00.000' AND INTERVALSTART <= '12/21/2013 08:00:00.000'

  • It would be helpful if you told us what issues you're experiencing.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Thanks for your response.

    My issue is that I am not able to get the correct values. The date range values are fine, but the times are off. I shouldn't see any time between work hours (8:00AM - 5:00PM), but I am still seeing those times.

    I hope this explains my issue.

  • Your problem is that you have not restricted the times as you wanted to.

    You're asking for values between 12/15/2013 17:00:00 and 12/21/2013 08:00:00 not between 12/15/2013 and 12/21/2013 only where the time is between 5:00PM and 8:00AM.

    You need to add another condition to the where clause that only looks at the time portion of the date and restrict that to only times between 5:00PM and 8:00AM.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Thanks Alvin. I will try that. Happy New Year to you and thanks for your time 🙂

  • You're welcome and Happy New Year to you too.

    Let us know if you have any more issues.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

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

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