diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/formulaFnHelper.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/formulaFnHelper.ts index e3268d7406..5a21ba3261 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/formulaFnHelper.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/formulaFnHelper.ts @@ -1,5 +1,8 @@ import dayjs, { extend } from 'dayjs'; import customParseFormat from 'dayjs/plugin/customParseFormat.js'; +import { UITypes } from 'nocodb-sdk'; +import Column from '../../../../../models/Column'; +import { convertDateFormat } from './convertDateFormat'; extend(customParseFormat); export function getWeekdayByText(v: string) { @@ -50,3 +53,45 @@ export function validateDateWithUnknownFormat(v: string) { } return false; } + +export async function convertDateFormatForConcat( + o, + columnIdToUidt, + query, + clientType +) { + if ( + o?.type === 'Identifier' && + o?.name in columnIdToUidt && + columnIdToUidt[o.name] === UITypes.Date + ) { + const meta = ( + await Column.get({ + colId: o.name, + }) + ).meta; + + if (clientType === 'mysql2') { + query = `DATE_FORMAT(${query}, '${convertDateFormat( + meta.date_format, + clientType + )}')`; + } else if (clientType === 'pg') { + query = `TO_CHAR(${query}, '${convertDateFormat( + meta.date_format, + clientType + )}')`; + } else if (clientType === 'sqlite3') { + query = `strftime('${convertDateFormat( + meta.date_format, + clientType + )}', ${query})`; + } else if (clientType === 'mssql') { + query = `FORMAT(${query}, '${convertDateFormat( + meta.date_format, + clientType + )}')`; + } + } + return query; +}