Date comparation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pemasem
    New Member
    • Oct 2007
    • 1

    Date comparation

    In my register I have "06/10/2007 12:41:02" DateTime value, but my query :

    SELECT Fecha
    FROM dbo.WWW_LIBROVI SITAS_VB
    WHERE (Fecha <= '06/10/2007 12:41:02') AND (Fecha >= '05/10/2007')
    ORDER BY Fecha DESC

    Doesn't return it.

    Why? Is not the same date?


    Help me please!!!
  • azimmer
    Recognized Expert New Member
    • Jul 2007
    • 200

    #2
    Originally posted by Pemasem
    In my register I have "06/10/2007 12:41:02" DateTime value, but my query :

    SELECT Fecha
    FROM dbo.WWW_LIBROVI SITAS_VB
    WHERE (Fecha <= '06/10/2007 12:41:02') AND (Fecha >= '05/10/2007')
    ORDER BY Fecha DESC

    Doesn't return it.

    Why? Is not the same date?


    Help me please!!!
    It may or may not be: if your date's fractional seconds are not zero it is actually larger... Also, make sure your system interpretes dates the same way you do: 06/10 may be June 10th or October 6th depending on settings; thus I suggest you enter where clauses in ISO format: '2007-06-10 12:41:02' for June 10th. (It is possible that date you see and date you enter by hand do not follow the same syntax.)

    Comment

    • iburyak
      Recognized Expert Top Contributor
      • Nov 2006
      • 1016

      #3
      Try this:


      [PHP]
      SELECT Fecha
      FROM dbo.WWW_LIBROVI SITAS_VB
      WHERE Fecha between dateadd(m, -1,'06/10/2007 12:41:02') and '06/10/2007 12:41:02'
      ORDER BY Fecha DESC[/PHP]


      Good Luck.

      Comment

      • iburyak
        Recognized Expert Top Contributor
        • Nov 2006
        • 1016

        #4
        Originally posted by Pemasem
        In my register I have "06/10/2007 12:41:02" DateTime value, but my query :

        SELECT Fecha
        FROM dbo.WWW_LIBROVI SITAS_VB
        WHERE (Fecha <= '06/10/2007 12:41:02') AND (Fecha >= '05/10/2007')
        ORDER BY Fecha DESC

        Doesn't return it.

        Why? Is not the same date?


        Help me please!!!
        By the way I checked your query and it does work with no problem.
        First time you just mention date and time and second time only date. Time in this case taken as default 00:00:00 so date is actually compared to
        '05/10/2007 00:00:00'

        Comment

        Working...