![]() |
Date range SQL querie not working?
This is what I'm using which, from what I have seen online, should be working:
Quote:
Any thoughts? |
Quote:
2. You are trying to compare a string to a date. You need to cast the strings as dates if you want a date compare. "where date between cast(date1 as date) and cast(date2 as date)" 3. Date is a keyword in MYSQL and should not be used as a variable name or field name. So where you have your column called date ("where Date...") should be something like "where order_date...." Or whatever other name the date is stored as. . |
Quote:
I renamed the column to showdate and also redid the syntax, which is strange as StackOverFlow had tons of people saying that worked as I posted lol Can you explain that part above for me a little? I'm not quite sure what you mean. |
MySQL (and PHP for that matter) does not magically recognize '2022-01-10' as a date. It's just a string with some numbers and hyphens in it. You can compare two strings but it's not the same as comparing dates. You have to tell it it's a date by casting it from "string" type to "date" type.
|
Sample of code which work for me:
PHP Code:
|
Edit : already posted above by Sarettah
:2 cents: |
So this is what I have now:
Quote:
The column is set to varchar(255) if that makes any difference? It isnt set as date, datetime, or anything like that, should it be? |
Quote:
|
Quote:
It should be "where ShowDate between......" Unless you are storing a string in the database instead of a date. In that case it would be "where cast(ShowDate as date) between.... . |
Quote:
Thank you :thumbsup |
Quote:
|
Quote:
|
Quote:
|
Thanks everyone, I have this working now :)
|
Quote:
|
All times are GMT -7. The time now is 01:00 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123