Viewing 10 posts - 1 through 10 (of 10 total)
  • Sql date/ time help
  • ebygomm
    Free Member

    If I want to test if a date/time is greater than 4am yesterday how would I go about doing it in sql?

    wilsation
    Free Member

    check for anything greater than todays date Minus 20hrs

    chvck
    Free Member

    datediff maybe( not sure if that’s t-sql specific)? Do you need to consider timezones at all?

    ebygomm
    Free Member

    to_char(start_date, ‘YYYYMMDDHH24MISS’) > to_ char(sysdate-1,’YYYYMMDD’)||’040000′

    works. I was sure I’d tried that before asking the question but must have had an error somewhere 🙂

    Torminalis
    Free Member

    easier:

    your_date > DATEADD(hh, -20, CAST(CAST(GETDATE() AS DATE) AS DATETIME))

    lemonysam
    Free Member

    to_char(start_date, ‘YYYYMMDDHH24MISS’) > to_ char(sysdate-1,’YYYYMMDD’)||’040000′

    Hang on, did you just call to_char on every record in the table? this is a one off right?

    /not an SQL guy

    ebygomm
    Free Member

    No use for Oracle though 🙂

    Torminalis
    Free Member

    ah, scope creep… 😆

    lemonysam
    Free Member

    Would something like this work?

    create_date >= TO_DATE(’28/01/2015 04:00:00.000000′,’MM/DD/YYYY HH24:MI:SS.FF’)

    /still not an SQL, let alone an oracle, guy

    DavidB
    Free Member

    create_date >= CURRENT_DATE – INTERVAL ‘1 DAY’ + INTERVAL ‘4 hours’

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘Sql date/ time help’ is closed to new replies.