07-14-2015 10:52 AM
Hi, i have a table with loads of dates.
I need a way to look this table everytime i run six months ago.
I use this Where my_date >= '14jul/2015:00:00:00'dt - 180;
But it does not work.
Rodrigo Dartibali Elias
07-14-2015 11:03 AM
It does work, what you are doing is subtracting 180 miliseconds from 14Jul2015 and then any date which is >= to that output. You need to understand how dates, times, and datetime variables are stored internally - read up in the manual on this. As for your problem, I would recommend using intck:
where my_date >= intck('month',datepart('14jul2015:00:00:00'dt),-6)
What this is doing is first, taking the datepart of the datetime variable as we are not interested in time part. Then it is using intck to move, as a monthly interval 6 months back, and finally using this date value as a comparison.