querybuilder icon indicating copy to clipboard operation
querybuilder copied to clipboard

Add date truncation support

Open SonicGD opened this issue 5 years ago • 0 comments

Hello. SqlKata already have WhereDatePart method, but it doesn't have something like WhereDateTrunc method to compare truncated dates. For example we need to check if Date is current month:

query.WhereDateTrunc("month", "Date", "=", DateTimeOffset.UtcNow);

and sql for this operation will be like this:

SQL Server

dateadd(MONTH, datediff(MONTH, 0, [Date]), 0) = dateadd(MONTH, datediff(MONTH, 0, @p0), 0) 

Postgres

date_trunc('month', "Date") = date_trunc('month', @p0)

Oracle also has trunc function, MySql can use DATE_FORMAT.

It would be nice to have such feature.

SonicGD avatar Apr 01 '20 07:04 SonicGD