There is a created_at
column of datetime
type in the order
table. In my application I'm storing dates to the db as datetime in UTC. When I bring them back from the db I'm presenting/formating them to the user as 'America/Tijuana'. Hence user input is expected in that timezone.
I'm very new to SQL programming, in fact I'm using the framework's integrated query building methods. Anyway, for "debugging" is what I am manually trying in phpmyadmin
SELECT * FROM `order` WHERE date(`created_at`) LIKE '%somedate%'
It works, but is comparing against UTC datetimes in the db. I want it to compare to 'America/Tijuana'.
I'm trying
SELECT * FROM `order`
WHERE date(convert_tz(`created_at`, 'UTC', 'America/tijuana')) LIKE '%30%'
which runs, but return 0 values. Am I doing it correctly?
LIKE
predicate, intended to compare strings, do adatetime
value.LC_TIME
.WHERE
clause is going to produce a non-sargable query. It's better to convert the right-hand side to UTC, then use that to query the column directly. Think about it - otherwise you literally have to convert every column in your table. The more rows you have in the table, the slower the query will be.