From efb58e8d31f08cd0c7f7e2d2ed724fee51845c56 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 13 Apr 2023 13:57:16 +0800 Subject: [PATCH] feat(nocodb): add convertDateFormat --- .../lib/sql/helpers/convertDateFormat.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/convertDateFormat.ts diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/convertDateFormat.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/convertDateFormat.ts new file mode 100644 index 0000000000..c9e833e3b3 --- /dev/null +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/convertDateFormat.ts @@ -0,0 +1,23 @@ +export function convertDateFormat(date_format: string, type: string) { + if (date_format === 'YYYY-MM-DD') { + if (type === 'mysql2' || type === 'sqlite') return '%Y-%m-%d'; + } else if (date_format === 'YYYY/MM/DD') { + if (type === 'mysql2' || type === 'sqlite') return '%Y/%m/%d'; + } else if (date_format === 'DD-MM-YYYY') { + if (type === 'mysql2' || type === 'sqlite') return '%d/%m/%Y'; + } else if (date_format === 'MM-DD-YYYY') { + if (type === 'mysql2' || type === 'sqlite') return '%d-%m-%Y'; + } else if (date_format === 'DD/MM/YYYY') { + if (type === 'mysql2' || type === 'sqlite') return '%d/%m/%Y'; + } else if (date_format === 'MM/DD/YYYY') { + if (type === 'mysql2' || type === 'sqlite') return '%m-%d-%Y'; + } else if (date_format === 'DD MM YYYY') { + if (type === 'mysql2' || type === 'sqlite') return '%d %m %Y'; + } else if (date_format === 'MM DD YYYY') { + if (type === 'mysql2' || type === 'sqlite') return '%m %d %Y'; + } else if (date_format === 'YYYY MM DD') { + if (type === 'mysql2' || type === 'sqlite') return '%Y %m %d'; + } + // pg / mssql + return date_format; +}