Kayserispor
Kayserispor

Reputation: 3

Sequelize Postgres how to set timezone gmt+1

Hi Stackoverflow Team,

i want to know, how can i set the timezone +01:00 for a timestamp, i can call all data entries with the neutral utc timezone... but i want to give a default timezone +01:00 Europe Berlin.

Even when i call my database table i want to get the right response. Thank you a lot for your answers..

const Sequelize = require('sequelize');
//CREATE DATABASE tai;
const sequelize = new Sequelize('tai', 'postgres', '', {
    //username: 'root',
    //password: 'root',
    dialect: 'postgres',
    logging: false,
    //storage: "./database.sqlite3",
    host: 'localhost',
    dialectOptions: { useUTC: false },
    typeCast: function (field, next) { // for reading from database
        if (field.type === 'DATETIME') {
            return field.string()
        }
        return next()
    },
    timezone: '+01:00',
    pool: {
        max: 2,
        min: 0,
        acquire: 10000,
        idle: 10000
    }
});

Upvotes: 0

Views: 3538

Answers (1)

In SQL, you'd change the time zone for either the server or for the client session. If you change the time zone for the client session, you have to do that for every client session, every time you start a new client session. (More or less.)

A change to the server configuration file (postgresql.conf, timezone = '' could be understood as changing the default for all client connections. Changing the server configuration file is the most robust approach, but you might not have access to it or privileges to change it.

Setting the PGTZ environment variable lets libpq clients send a SET TIME ZONE command to the server when they connect connection. That could be understood as changing the default for one client.

Executing the SQL set time zone changes the time zone for a session. So that could be understood as changing the default for one client session.

For Sequelize, I think you want to use options.timezone (search this page for timezone), and you probably want to use "Europe/Berlin" rather than a literal, fixed offset.

Upvotes: 1

Related Questions