John Davidson

php - mysql 8 using a wildcard in query when selecting a date

0 comments
Message:


Im currently using this query:


General error: 1525 Incorrect DATE value: '2020-02%'
The SQL being executed was: SELECT
'01',
2103,
cssd._campaign_id,
cssd.first,
cssd.last,
cssd.street,
cssd.city,
cssd.state,
cssd.zip,
cssd.customer_id,
cssd.vin,
cssd.email,
cssd.phone,
cssd.phone2,
cssd.phonecell
FROM combined_sales_service_data cssd
WHERE cssd._campaign_id = 25
AND cssd.last_date >= '2020-02%'

last_date is a DATE field.


Which used to work in 5.7, however in 8.0 i'm getting the date error above.


Now I can update the date to 2020-02-01 but I would like to be able to use the wildcard in some situations.


Is there a better way to formulate this statement without setting the ALLOW_INVALID_DATES


Thanks



My Answer:
LIKE '2020-02%'

You can use the LIKE operator with a wildcard (%) to select dates that start with '2020-02'. This will match any date in February 2020.

Rate this post

5 of 5 based on 4612 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us