Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node with Mysql2 timezone issue

When I am trying to set the timezone with mysql2 getting the bellow message. With MySQL working fine.

But I have to use mysql2 only

var mysql2 = require('mysql2');

var con = mysql2.createPool({  
connectionLimit : 10, 
host: process.env.DATABASE_HOST, 
user: process.env.DATABASE_USER,  
password: process.env.DATABASE_PASSWORD,  
database : process.env.DATABASE_NAME,  
timezone : 'IST'      
})

Problem

Ignoring invalid timezone passed to Connection: IST. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you give an invalid configuration option to a Connection

like image 361
Sujeet Kumar Avatar asked Aug 31 '25 15:08

Sujeet Kumar


2 Answers

You can find the description about timezone in mysqljs/mysql:

timezone: The timezone configured on the MySQL server. This is used to type cast server date/time values to JavaScript Date object and vice versa. This can be 'local', 'Z', or an offset in the form +HH:MM or -HH:MM. (Default: 'local')

You need to use +05:30 instead of Asia/Calcutta.

like image 165
Tura Avatar answered Sep 02 '25 11:09

Tura


Here try this as timezone. For IST

timezone: 'Asia/Calcutta'

or

timezone: '+05:30'
like image 32
xMayank Avatar answered Sep 02 '25 11:09

xMayank