Query with dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • daniel aristidou
    Contributor
    • Aug 2007
    • 494

    Query with dates

    Hi im a bit stuck on querying with dates. ive got a databse that querries using sql in visual basic 6.

    I need to select only the dates which have passed or are today.
    But the query returns all the records regardless of if the date has not passed

    eg
    Code:
    todaydate = format(date, "dd/mm/yyyy")
    frmCars.Cars_Data.RecordSource = "select *  from car_Rentals WHERE  (Format(due_service,'dd/mm/yyyy') >= " & "'" & todaydate & "') And (Format(due_service,'dd/mm/yyyy') = " & "'" & todaydate & "')"
    frmcars.cars_data.refresh
    I also tried like this
    Code:
    todaydate = format(date, "dd/mm/yyyy")
    frmCars.Cars_Data.RecordSource = "select *  from car_Rentals WHERE  (Format(due_service,'dd/mm/yyyy') > " & "'" & todaydate & "') And (Format(due_service,'dd/mm/yyyy') = " & "'" & todaydate & "')"
    frmcars.cars_data.refresh
    And like this

    Code:
    todaydate = format(date, "dd/mm/yyyy")
    frmCars.Cars_Data.RecordSource = "select *  from car_Rentals WHERE  (Format(due_service,'dd/mm/yyyy') >= " & "'" & todaydate & "'"
    frmcars.cars_data.refresh
    They all had a result either consisting only of one that was equl to the current date or all of the records.



    in advance Thanks ........Extreme ly Thankfull for any tips
  • lotus18
    Contributor
    • Nov 2007
    • 865

    #2
    Originally posted by daniel aristidou
    Hi im a bit stuck on querying with dates. ive got a databse that querries using sql in visual basic 6.

    I need to select only the dates which have passed or are today.
    But the query returns all the records regardless of if the date has not passed

    eg
    Code:
    todaydate = format(date, "dd/mm/yyyy")
    frmCars.Cars_Data.RecordSource = "select *  from car_Rentals WHERE  (Format(due_service,'dd/mm/yyyy') >= " & "'" & todaydate & "') And (Format(due_service,'dd/mm/yyyy') = " & "'" & todaydate & "')"
    frmcars.cars_data.refresh
    I also tried like this
    Code:
    todaydate = format(date, "dd/mm/yyyy")
    frmCars.Cars_Data.RecordSource = "select *  from car_Rentals WHERE  (Format(due_service,'dd/mm/yyyy') > " & "'" & todaydate & "') And (Format(due_service,'dd/mm/yyyy') = " & "'" & todaydate & "')"
    frmcars.cars_data.refresh
    And like this

    Code:
    todaydate = format(date, "dd/mm/yyyy")
    frmCars.Cars_Data.RecordSource = "select *  from car_Rentals WHERE  (Format(due_service,'dd/mm/yyyy') >= " & "'" & todaydate & "'"
    frmcars.cars_data.refresh
    They all had a result either consisting only of one that was equl to the current date or all of the records.



    in advance Thanks ........Extreme ly Thankfull for any tips
    Try to use Between...And Operator

    Comment

    • creative1
      Contributor
      • Sep 2007
      • 274

      #3
      use # instead of & around date fields

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        Originally posted by daniel aristidou
        I need to select only the dates which have passed or are today.
        as per your statment , what about using OR operator instead of AND in the sql statment.

        Comment

        • daniel aristidou
          Contributor
          • Aug 2007
          • 494

          #5
          Originally posted by debasisdas
          as per your statment , what about using OR operator instead of AND in the sql statment.
          Thanks for your replies ill try them out thanks il psot again if ang problems
          Ps i did you or as well........ i reckd my brains out lookin for solution

          Comment

          • daniel aristidou
            Contributor
            • Aug 2007
            • 494

            #6
            Hi guys......
            I tried to change the & to # but this did not work it kept on comming up with error messages. Can someone please post the code that is correct cause im also confused as to which bit i have to apply the #.

            Thanks.....
            Also regarding the post mentioning between. i tried it but am not familiar with how it works.

            Comment

            • daniel aristidou
              Contributor
              • Aug 2007
              • 494

              #7
              Originally posted by daniel aristidou
              Hi guys......
              I tried to change the & to # but this did not work it kept on comming up with error messages. Can someone please post the code that is correct cause im also confused as to which bit i have to apply the #.

              Thanks.....
              Also regarding the post mentioning between. i tried it but am not familiar with how it works.
              Ps please note this is for my a level so only teech me how to put the # in ect
              Thanks

              Comment

              • lotus18
                Contributor
                • Nov 2007
                • 865

                #8
                Hi Daniel

                Does your due_service and todaydate are of both date datatypes? Try to omit the format function then in the general tab, format property of due_service select shortdate. : )

                Comment

                Working...