Skip to main content

I can't seem to find an expression operator to subtract months / years from a date.

 

In sql normally I'd run a DateAdd(month, - 6, date) or DateAdd(day, -7) to get my comparison.

 

Is there a good way to do this?
I have a Stored Procedure to populate a list based on a range between dates.


Today / last week / last 30 days / last 6 months / last year

Using radio buttons I want to auto populate parameters with my dates (auto set my expressions)

 

I got Today / 7 days from today / 30 days ago from today to work. 

 

15766iA0C55D9472C50A60.png

 

 

Hi,


 


There should an expression that allows you to calculate date/time difference. You should be able to specify the interval you want. You can refer to here for more information.


I was trying that - but I can't get it to do DayTimeDifference(Month,  Current Day - 6 Months, Current Day)

 

That's what I'm trying to do.

In SQL I would do this: select CONVERT(VARCHAR(10),dateadd(month,-6,SYSDATETIME()))

 

It shows up as -1 or blank when I try in K2.

 


The Date Diff expression only calculates the difference between 2 dates. My bad, as I thought you only want the difference between two dates.


 


There isn't any expression that can allow you to subtract months from a date. The only workaround I can think of is to create a stored procedure in your database that acccepts a date, and the number of months to subtract, then return the results. After that, create a SmartObject from that stored procedure, and call that SmartObject whenever you need to perform the calculation.


 


I ended up creating 3 stored procedures to accomodate my needs.  1 to filter based on actual days input by calendar controls or specific expressions like the (Today, Last 7 Days, Last 30 Days)

1 for Last 6 months where the stored procedure has my pre set filters

1 for Last year where the stored procedure has my pre set filters.

 

It would be great if K2 would just add in a Subtract Months / Years to the Operators list like the Subtract Days, Minutes, Hours.  


Reply