Date time difference

  • Hi

    I have RegDateTime column of DateTime datatype.

    which is storing registration date time of user.

    I want to display all users that are registered within 24 hrs.

    This should work for AM and PM

    How to write query for this?

    Thanks in advance.

  • HI There,

    Could you show us what you have so far.

    HINT:

    This is going to require a where clause with the GETDATE() function in it

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • I am using this :

    select * from users

    where regdatetime > Dateadd(hour,-24,getdate())

    Will this give correct result :

    if suppose user registers at 11 pm of 15 sep

    and if I see the result at 01 am of 16 sep

  • That looks good.

    Prob a good idea to also do some testing with different examples with different times that are greater, less and equal to your getdate value.

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life

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

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