Convert created_at value to another timezone before saving


#1

I have a query to how to convert the created_at date value to any specific timezone (ex. UTC) while saving the new record.

  • I am using the increments/timestamp to create the created_at field in the database. The values of created_at and updated_at fields will be generated according to the server timezone by the adonis. But i need to change the timezone of the created_at value before saving the record.

  • I have already tried a solution found in knex.js but it is also not working.

connection: {

timezone: ‘UTC’,
typeCast: function (field, next) {
if (field.type == ‘DATETIME’) {
return moment(field.string()).format(‘YYYY-MM-DD HH:mm:ss’);
}
return next();
}
}

Thanks in advance!