Date Query Problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • carverk@hotmail.com

    #1

    Date Query Problems

    Hello All

    I'm in the middle of moving a MS Access DB to a MySql backend.
    I have figured out about 90% of the problems I have faced, execpt
    for this one.

    I have 3 Queries, which pull records depending on a date range.
    (Today,Last 7 Days,Next 7 Days) The one I'm having problems with
    is the "Last 7 Days" Query.

    Here's the Criteria I'm Using: Between Date() And DateAdd("d",-7,Date())

    When the tables are in access things work Fine, but when the tables
    are in MySql the Query doesn't work. Changing things a little and
    playing around with the criteria, it looks like MySql/MyODBC or
    something doesn't like the "-7" part, as when I make the # a non
    negitive value the query works.

    I have tried for the last 2 days changing the Criteria to work
    but I can't seem to get it working. Can any of your wonderfull
    people help?

    PS: The "Next 7 Days" query is the same as above only removing the "-"
  • Barry

    #2
    Re: Date Query Problems

    You need to use DATE_SUB(Date() , INTERVAL 7 DAY)


    carverk@hotmail .com wrote:
    [color=blue]
    >Hello All
    >
    >I'm in the middle of moving a MS Access DB to a MySql backend.
    >I have figured out about 90% of the problems I have faced, execpt
    >for this one.
    >
    >I have 3 Queries, which pull records depending on a date range.
    >(Today,Last 7 Days,Next 7 Days) The one I'm having problems with
    >is the "Last 7 Days" Query.
    >
    >Here's the Criteria I'm Using: Between Date() And DateAdd("d",-7,Date())
    >
    >When the tables are in access things work Fine, but when the tables
    >are in MySql the Query doesn't work. Changing things a little and
    >playing around with the criteria, it looks like MySql/MyODBC or
    >something doesn't like the "-7" part, as when I make the # a non
    >negitive value the query works.
    >
    >I have tried for the last 2 days changing the Criteria to work
    >but I can't seem to get it working. Can any of your wonderfull
    >people help?
    >
    >PS: The "Next 7 Days" query is the same as above only removing the "-"
    >
    >[/color]

    Comment

    • Barry

      #3
      Re: Date Query Problems

      You need to use DATE_SUB(Date() , INTERVAL 7 DAY)


      carverk@hotmail .com wrote:
      [color=blue]
      >Hello All
      >
      >I'm in the middle of moving a MS Access DB to a MySql backend.
      >I have figured out about 90% of the problems I have faced, execpt
      >for this one.
      >
      >I have 3 Queries, which pull records depending on a date range.
      >(Today,Last 7 Days,Next 7 Days) The one I'm having problems with
      >is the "Last 7 Days" Query.
      >
      >Here's the Criteria I'm Using: Between Date() And DateAdd("d",-7,Date())
      >
      >When the tables are in access things work Fine, but when the tables
      >are in MySql the Query doesn't work. Changing things a little and
      >playing around with the criteria, it looks like MySql/MyODBC or
      >something doesn't like the "-7" part, as when I make the # a non
      >negitive value the query works.
      >
      >I have tried for the last 2 days changing the Criteria to work
      >but I can't seem to get it working. Can any of your wonderfull
      >people help?
      >
      >PS: The "Next 7 Days" query is the same as above only removing the "-"
      >
      >[/color]

      Comment

      • carverk@hotmail.com

        #4
        Re: Date Query Problems

        Hello,

        Thanks for the Info. However when I past this into the
        Access Query Windows "Critera" field and try to run the
        query I get "Undefined "DATE_SUB" In Expression".




        Barry <barry@nospampp solutions.co.uk > wrote in message news:<3FC3287A. 8070202@nospamp psolutions.co.u k>...[color=blue]
        > You need to use DATE_SUB(Date() , INTERVAL 7 DAY)
        >
        >
        > carverk@hotmail .com wrote:
        >[color=green]
        > >Hello All
        > >
        > >I'm in the middle of moving a MS Access DB to a MySql backend.
        > >I have figured out about 90% of the problems I have faced, execpt
        > >for this one.
        > >
        > >I have 3 Queries, which pull records depending on a date range.
        > >(Today,Last 7 Days,Next 7 Days) The one I'm having problems with
        > >is the "Last 7 Days" Query.
        > >
        > >Here's the Criteria I'm Using: Between Date() And DateAdd("d",-7,Date())
        > >
        > >When the tables are in access things work Fine, but when the tables
        > >are in MySql the Query doesn't work. Changing things a little and
        > >playing around with the criteria, it looks like MySql/MyODBC or
        > >something doesn't like the "-7" part, as when I make the # a non
        > >negitive value the query works.
        > >
        > >I have tried for the last 2 days changing the Criteria to work
        > >but I can't seem to get it working. Can any of your wonderfull
        > >people help?
        > >
        > >PS: The "Next 7 Days" query is the same as above only removing the "-"
        > >
        > >[/color][/color]

        Comment

        • carverk@hotmail.com

          #5
          Re: Date Query Problems

          Hello,

          Thanks for the Info. However when I past this into the
          Access Query Windows "Critera" field and try to run the
          query I get "Undefined "DATE_SUB" In Expression".




          Barry <barry@nospampp solutions.co.uk > wrote in message news:<3FC3287A. 8070202@nospamp psolutions.co.u k>...[color=blue]
          > You need to use DATE_SUB(Date() , INTERVAL 7 DAY)
          >
          >
          > carverk@hotmail .com wrote:
          >[color=green]
          > >Hello All
          > >
          > >I'm in the middle of moving a MS Access DB to a MySql backend.
          > >I have figured out about 90% of the problems I have faced, execpt
          > >for this one.
          > >
          > >I have 3 Queries, which pull records depending on a date range.
          > >(Today,Last 7 Days,Next 7 Days) The one I'm having problems with
          > >is the "Last 7 Days" Query.
          > >
          > >Here's the Criteria I'm Using: Between Date() And DateAdd("d",-7,Date())
          > >
          > >When the tables are in access things work Fine, but when the tables
          > >are in MySql the Query doesn't work. Changing things a little and
          > >playing around with the criteria, it looks like MySql/MyODBC or
          > >something doesn't like the "-7" part, as when I make the # a non
          > >negitive value the query works.
          > >
          > >I have tried for the last 2 days changing the Criteria to work
          > >but I can't seem to get it working. Can any of your wonderfull
          > >people help?
          > >
          > >PS: The "Next 7 Days" query is the same as above only removing the "-"
          > >
          > >[/color][/color]

          Comment

          • Barry

            #6
            Re: Date Query Problems

            DATE_SUB is a function of MySQL so won't work in Access. I thought you
            were moving from Access to MySQL so assumed you would need the MySQL
            function.

            carverk@hotmail .com wrote:
            [color=blue]
            >Hello,
            >
            >Thanks for the Info. However when I past this into the
            >Access Query Windows "Critera" field and try to run the
            >query I get "Undefined "DATE_SUB" In Expression".
            >
            >
            >
            >
            >Barry <barry@nospampp solutions.co.uk > wrote in message news:<3FC3287A. 8070202@nospamp psolutions.co.u k>...
            >
            >[color=green]
            >>You need to use DATE_SUB(Date() , INTERVAL 7 DAY)
            >>
            >>
            >>carverk@hotma il.com wrote:
            >>
            >>
            >>[color=darkred]
            >>>Hello All
            >>>
            >>>I'm in the middle of moving a MS Access DB to a MySql backend.
            >>>I have figured out about 90% of the problems I have faced, execpt
            >>>for this one.
            >>>
            >>>I have 3 Queries, which pull records depending on a date range.
            >>>(Today,Las t 7 Days,Next 7 Days) The one I'm having problems with
            >>>is the "Last 7 Days" Query.
            >>>
            >>>Here's the Criteria I'm Using: Between Date() And DateAdd("d",-7,Date())
            >>>
            >>>When the tables are in access things work Fine, but when the tables
            >>>are in MySql the Query doesn't work. Changing things a little and
            >>>playing around with the criteria, it looks like MySql/MyODBC or
            >>>something doesn't like the "-7" part, as when I make the # a non
            >>>negitive value the query works.
            >>>
            >>>I have tried for the last 2 days changing the Criteria to work
            >>>but I can't seem to get it working. Can any of your wonderfull
            >>>people help?
            >>>
            >>>PS: The "Next 7 Days" query is the same as above only removing the "-"
            >>>
            >>>
            >>>
            >>>[/color][/color][/color]

            Comment

            • Barry

              #7
              Re: Date Query Problems

              DATE_SUB is a function of MySQL so won't work in Access. I thought you
              were moving from Access to MySQL so assumed you would need the MySQL
              function.

              carverk@hotmail .com wrote:
              [color=blue]
              >Hello,
              >
              >Thanks for the Info. However when I past this into the
              >Access Query Windows "Critera" field and try to run the
              >query I get "Undefined "DATE_SUB" In Expression".
              >
              >
              >
              >
              >Barry <barry@nospampp solutions.co.uk > wrote in message news:<3FC3287A. 8070202@nospamp psolutions.co.u k>...
              >
              >[color=green]
              >>You need to use DATE_SUB(Date() , INTERVAL 7 DAY)
              >>
              >>
              >>carverk@hotma il.com wrote:
              >>
              >>
              >>[color=darkred]
              >>>Hello All
              >>>
              >>>I'm in the middle of moving a MS Access DB to a MySql backend.
              >>>I have figured out about 90% of the problems I have faced, execpt
              >>>for this one.
              >>>
              >>>I have 3 Queries, which pull records depending on a date range.
              >>>(Today,Las t 7 Days,Next 7 Days) The one I'm having problems with
              >>>is the "Last 7 Days" Query.
              >>>
              >>>Here's the Criteria I'm Using: Between Date() And DateAdd("d",-7,Date())
              >>>
              >>>When the tables are in access things work Fine, but when the tables
              >>>are in MySql the Query doesn't work. Changing things a little and
              >>>playing around with the criteria, it looks like MySql/MyODBC or
              >>>something doesn't like the "-7" part, as when I make the # a non
              >>>negitive value the query works.
              >>>
              >>>I have tried for the last 2 days changing the Criteria to work
              >>>but I can't seem to get it working. Can any of your wonderfull
              >>>people help?
              >>>
              >>>PS: The "Next 7 Days" query is the same as above only removing the "-"
              >>>
              >>>
              >>>
              >>>[/color][/color][/color]

              Comment

              Working...