php/mysql and dates

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob

    php/mysql and dates

    This little date formating problem is holding me up!

    Here is the sql query string.

    .....

    WHERE
    (`work_orders`. `date_closed` > $ > $start_date)
    AND (`work_orders`. `date_closed` < $end_date)
    ORDER BY
    (`work_orders`. `date_closed`)" ;

    The dates are in the 2005-05-16 format already.
    A typical start_date might be: 2005-05-11 with end_date of 2005-05-16

    I get no results returned even though there are records that meet that
    criteria.

    help please.

    bob

  • Oli Filth

    #2
    Re: php/mysql and dates


    Bob wrote:[color=blue]
    > This little date formating problem is holding me up!
    >
    > Here is the sql query string.
    >
    > ....
    >
    > WHERE
    > (`work_orders`. `date_closed` > $ > $start_date)[/color]
    ^
    ^
    Are you sure you meant this dollar sign to be here?
    [color=blue]
    > AND (`work_orders`. `date_closed` < $end_date)
    > ORDER BY
    > (`work_orders`. `date_closed`)" ;
    >
    > The dates are in the 2005-05-16 format already.
    > A typical start_date might be: 2005-05-11 with end_date of 2005-05-16
    >[/color]

    Dates and times need to be delimited with single quotes in SQL queries.

    If a MySQL call doesn't work, either turn on mysql.trace_mod e the
    directive, or echo a mysql_error() call to find out what the problem
    is!!

    --
    Oli

    Comment

    • Bob

      #3
      Re: php/mysql and dates

      I don't know how that $ got in there, it's not in the code. And it
      doesn't work with out the $ either. The sql string is as follows:


      SELECT `work_orders`.` Work_Order_Numb er`, `work_orders`.` Date_Opened`,
      `customers`.`la st_name`, `work_orders`.` Due_date`,
      `work_orders`.` priority`, `work_orders`.` Part_Number`,
      `work_orders`.` Qty`, `work_orders`.` Qty_Shipped`,
      `work_orders`.` Value`, `part_numbers`. `part_number`,
      `part_numbers`. `part_number_su b`, `part_numbers`. `description`,
      `part_numbers`. `qty_in_invento ry` FROM `customers`, `work_orders`,
      `part_numbers` WHERE (`work_orders`. `date_closed` > 2005-05-01) AND
      (`work_orders`. `date_closed` < 2005-05-17)


      which returns:

      Number of work orders in database= 0

      Comment

      • Oli Filth

        #4
        Re: php/mysql and dates

        Bob wrote:[color=blue]
        > I don't know how that $ got in there, it's not in the code. And it
        > doesn't work with out the $ either. The sql string is as follows:
        >
        >
        > SELECT `work_orders`.` Work_Order_Numb er`,[/color]
        `work_orders`.` Date_Opened`,[color=blue]
        > `customers`.`la st_name`, `work_orders`.` Due_date`,
        > `work_orders`.` priority`, `work_orders`.` Part_Number`,
        > `work_orders`.` Qty`, `work_orders`.` Qty_Shipped`,
        > `work_orders`.` Value`, `part_numbers`. `part_number`,
        > `part_numbers`. `part_number_su b`, `part_numbers`. `description`,
        > `part_numbers`. `qty_in_invento ry` FROM `customers`, `work_orders`,
        > `part_numbers` WHERE (`work_orders`. `date_closed` > 2005-05-01) AND
        > (`work_orders`. `date_closed` < 2005-05-17)
        >[/color]

        Did you read the second half of my previous comment??

        --
        Oli

        Comment

        • Bob

          #5
          Re: php/mysql and dates

          Yes, I did. But I'll have to read up on those mysql commands.
          I am not familiar with them.
          I was assuming the sql query was working, but that I was not
          structuring the query the correctly.



          Oli Filth wrote:[color=blue]
          > Bob wrote:[color=green]
          > > I don't know how that $ got in there, it's not in the code. And it
          > > doesn't work with out the $ either. The sql string is as follows:
          > >
          > >
          > > SELECT `work_orders`.` Work_Order_Numb er`,[/color]
          > `work_orders`.` Date_Opened`,[color=green]
          > > `customers`.`la st_name`, `work_orders`.` Due_date`,
          > > `work_orders`.` priority`, `work_orders`.` Part_Number`,
          > > `work_orders`.` Qty`, `work_orders`.` Qty_Shipped`,
          > > `work_orders`.` Value`, `part_numbers`. `part_number`,
          > > `part_numbers`. `part_number_su b`, `part_numbers`. `description`,
          > > `part_numbers`. `qty_in_invento ry` FROM `customers`, `work_orders`,
          > > `part_numbers` WHERE (`work_orders`. `date_closed` > 2005-05-01) AND
          > > (`work_orders`. `date_closed` < 2005-05-17)
          > >[/color]
          >
          > Did you read the second half of my previous comment??
          >
          > --
          > Oli[/color]

          Comment

          • Oli Filth

            #6
            Re: php/mysql and dates

            Bob wrote:[color=blue]
            > Oli Filth wrote:[color=green]
            > > Did you read the second half of my previous comment??[/color]
            >
            > Yes, I did. But I'll have to read up on those mysql commands.
            > I am not familiar with them.[/color]

            More relevant than that, the bit about having to delimit date strings
            in MySQL with single quotes.
            [color=blue]
            > I was assuming the sql query was working, but that I was not
            > structuring the query the correctly.[/color]

            I can tell you right now, it wasn't correct, because of the date thing.



            --
            Oli

            Comment

            Working...