Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql date comparison using BETWEEN in MySQL JSON data

I'm struggling to compare dates which are stored in JSON data in MySQL.

The format of the JSON would be something like

{"0": {"end_date": "2018/06/30", "start_date": "2018/06/01"}, "1": {"end_date": "2018/06/30", "start_date": "2018/06/01"}}

So, now I need to write a MySQL query to fetch the row only if the date in the JSON is BETWEEN '2018/06/01' and '2018/06/05'.

Any alternate suggestions instead of storing in JSON also welcome.

like image 728
Tarun Parswani Avatar asked Mar 06 '26 22:03

Tarun Parswani


1 Answers

I would be tempted to use generated columns on start data and end date to make the SQL much easier.

like image 100
Dave Stokes Avatar answered Mar 09 '26 10:03

Dave Stokes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!