diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index c819a8278e..b836a56460 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -3306,6 +3306,7 @@ class BaseModelSqlv2 { if (this.isSqlite) { if (!col.cdf) { if ( + d[col.title].indexOf('-') === -1 && d[col.title].indexOf('+') === -1 && d[col.title].slice(-1) !== 'Z' ) { diff --git a/packages/nocodb/src/models/Model.ts b/packages/nocodb/src/models/Model.ts index 0de492b0fe..e9d552d764 100644 --- a/packages/nocodb/src/models/Model.ts +++ b/packages/nocodb/src/models/Model.ts @@ -469,7 +469,11 @@ export default class Model implements TableType { } if (col.uidt === UITypes.DateTime && dayjs(val).isValid()) { const { isMySQL, isSqlite, isMssql, isPg } = clientMeta; - if (val.indexOf('+') < 0 && val.slice(-1) !== 'Z') { + if ( + val.indexOf('-') < 0 && + val.indexOf('+') < 0 && + val.slice(-1) !== 'Z' + ) { // if no timezone is given, // then append +00:00 to make it as UTC val += '+00:00'; @@ -494,11 +498,11 @@ export default class Model implements TableType { // e.g. 2022-01-01T10:00:00.000Z -> 2022-01-01 04:30:00+00:00 val = dayjs(val).utc().format('YYYY-MM-DD HH:mm:ssZ'); } else if (isPg) { - // convert to local time - // e.g. 2023-01-01T12:00:00.000Z -> 2023-01-01 20:00:00+08:00 - // convert to db timezone + // convert to UTC + // e.g. 2023-01-01T12:00:00.000Z -> 2023-01-01 12:00:00+00:00 + // then convert to db timezone val = knex.raw(`? AT TIME ZONE CURRENT_SETTING('timezone')`, [ - dayjs(val).format('YYYY-MM-DD HH:mm:ssZ'), + dayjs(val).utc().format('YYYY-MM-DD HH:mm:ssZ'), ]); } else if (isMssql) { // e.g. 2023-05-10T08:49:32.000Z -> 2023-05-10 08:49:32-08:00