I'm connecting to mySQL using express, and anytime I try to use any DATE functions it always evaluates to one day earlier than the provided date and always at 5pm
For example:
connection.query('SELECT DATE("2001-02-15")', (err, rows, fields) => console.log(rows))
This gives the output:
[ RowDataPacket { 'DATE("2001-02-15")': 2001-02-14T17:00:00.000Z } ]
Another example when I ran this on July 3:
connection.query('SELECT CURDATE()', (err, rows, fields) => console.log(rows))
[ RowDataPacket { 'CURDATE()': 2023-07-02T17:00:00.000Z } ]
Using the mySQL shell gives me the correct date though:
+------------+
| CURDATE() |
+------------+
| 2023-07-03 |
+------------+
1 row in set (0.0008 sec)
My mySQL server is using my system's time zone, which is set to UTC +7, and the system_time_zone variable in mySQL workbench says SE Asia Standard Time. Anyone have any idea what's going on?
Edit: worth noting that using NOW() gives a time 7hours earlier than my time, which suggests ExpressJS is for some reason in UTC+0 (my time currently is 7:32)
connection.query('SELECT NOW()', (err, rows, fields) => console.log(rows))
[ RowDataPacket { 'NOW()': 2023-07-03T12:31:13.000Z } ]
query for time zone
SELECT @@global.time_zone, @@session.time_zone;
+--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| SYSTEM | SYSTEM |
+--------------------+---------------------+
i think they both use system time zone, which is UTC+7 according to my laptop's time zone settings