I have dates stored as a varchar in a MySQL database. I know this isn't ideal.. but it what's I have at the moment.
Example date:
$start_date = "11/22/2019";
$start_date = strtotime($start_date);
$end_date = "11/29/2020";
$end_date = strtotime($end_date);
I'm trying to write a query that checks to see if a date in this format falls within a range
I'm running into problems when the start date has the same month as the end date but a different year.
if (!empty($start_date)) {
$where_clause[] = "UNIX_TIMESTAMP(start_date) >= '" . $start_date . "'";
}
if (!empty($end_date)) {
$where_clause[] = "UNIX_TIMESTAMP(end_date) <= '" . $end_date . "'";
}
I read that UNIX_TIMESTAMP would allow me to do this but it doesn't seem to be working.
How can I make this query work?
2019-11-22(yyyy-mm-dd) then pass it as parameters of UNIX_TIMESTAMP. It doesn't accept any date format unless you convert it. w3resource.com/mysql/date-and-time-functions/…