Skip to content

Commit

Permalink
feat: allow custom date formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchamp-saqib committed Mar 9, 2024
1 parent 59399e3 commit 95826e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions frontend/src/utils/query/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ export const FUNCTIONS = {
example: '`invoice.posting_date` = today()',
returnType: 'date',
},
format_date: {
syntax: 'format_date(date, "format")',
description: 'Formats date to the given format.',
example: 'format_date(`invoice.posting_date`, "DD-MM-YYYY")',
returnType: 'string',
},
start_of: {
syntax: 'start_of(unit, date)',
description: 'Finds start of the given unit (e.g., Month, Year).',
Expand Down
2 changes: 2 additions & 0 deletions insights/insights/query_builders/sql_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def format_date(cls, format, column: Column):
),
"%Y-%m-%d",
)
else:
return func.date_format(column, format)


class Functions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def format_date(cls, format, column: Column):
date,
("-" + func.mod((month - 1), 3) + " months"),
)
else:
return func.strftime(format, column)

return column

Expand Down

0 comments on commit 95826e3

Please sign in to comment.