Who's online?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rev2red
    New Member
    • Aug 2007
    • 4

    Who's online?

    I have a table of users and a table consisting of logins which I'm joining together. I'm trying to query the users who have logged in within the past 20 minutes. I've been attempting to use the datediff function such as:
    DateDiff("M", MyDateTime1, MyDateTime2)
    but I'm unclear about a couple of things.

    One, does the dateDiff function account for different years and hours, meaning does the datediff function drop year and days and only looks at the minutes?

    For example, say I have an entry at:
    08/01/2007 10:10:10 and
    08/01/2008 10:20:10
    and assume the datetime now is 08/01/2008 10:22:10. Would the results returned be 2 or 1?

    Is there a better function to use? If so, what is it and I'll research it.

    Thank,
    Red
  • Purple
    Recognized Expert Contributor
    • May 2007
    • 404

    #2
    Hi Red and welcome to TSDN MSSQL forum,

    can I direct you first to the microsoft reference on the datediff function here .

    From your description the function will do what you need, take a read and ask back for clarification

    Regards Purple

    Comment

    • rev2red
      New Member
      • Aug 2007
      • 4

      #3
      Thank you for the link!

      Comment

      • rev2red
        New Member
        • Aug 2007
        • 4

        #4
        Okay, so I read the MS reference and the very first sentence,

        datepart
        Is the parameter that specifies on which part of the date to calculate the difference.
        sounds as if it ONLY subtracts the datepart only and that is disregards the other parts...

        e.g. if you are searching for the datepart of month, then the year and seconds are disregarded. Is this a true statement?

        Comment

        • ck9663
          Recognized Expert Specialist
          • Jun 2007
          • 2878

          #5
          Originally posted by rev2red
          Okay, so I read the MS reference and the very first sentence,


          sounds as if it ONLY subtracts the datepart only and that is disregards the other parts...

          e.g. if you are searching for the datepart of month, then the year and seconds are disregarded. Is this a true statement?
          The DATEDIFF function calculates the period of time in dateparts between the second and first of two dates you specify.

          DATEDIFF(datepa rt, date1, date2)

          This function will result a date2-date1 in date parts. It returns the interval between the two dates depending on what datepart you're trying to get.

          if you want the number of days between date1 and date2 try DATEDIFF(dd, date1, date2). it will return the number of days.

          if you want the number of weeks between date1 and date2 try DATEDIFF(wk, date1, date2). it will return an integer representing the number of weeks between the two dates.

          so depending on what you're trying to get, you have to change the datepart parameter. if you read past the first sentence, you would know ;)

          Comment

          Working...