Jump to content

Recommended Posts

i cant seem to get a query working using  name and date range (between start and end date)

all values are in the tables mysql doesnt return an error

any ideas?

mysql 5

php 5.2.8

 

$sql_query="SELECT recnum FROM sc_income WHERE ( full_name = 'gary' AND ( service_date >= '01/01/2009' AND service_date <= '08/01/2009') ) ";

Link to comment
https://forums.phpfreaks.com/topic/170092-solved-date-range-query/
Share on other sites

You CANNOT do greater-than/less-than date comparisons using that format '01/01/2009' because the fields that make up that format are not ordered left-to-right, MSD (Most Significant Digit - YEAR) to LSD (Least Significant Digit - DAY).

 

You need to use a DATE data type YYYY-MM-DD to get greater-than/less-than date comparisons to work. A DATE data type will also use less storage than the format you are currently using.

01/01/2009 is not a valid date format. If you have service_date as a varchar field then you have made an error. It must be of type DATE (YYYY-MM-DD) to use operators on. Essentially this is a string '01/01/2009' so how can it be greater or less than another value?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.