Обсуждение: Help With date/time
Hi, I want to remove data that is older that a certain number of months.. only full months. example: today is 11-08 and I want do delete all data that is older than this month - 3 month i.e. i want to delete all information that is older than Aug. 1st. Is there an easy way to do that ? Interval cannot be used and I cannot just pass something like now()::date < '2003-08' Thanks for any help here Alex
On Sun, Nov 09, 2003 at 02:04:22 +0900, Alex <alex@meerkatsoft.com> wrote: > Hi, > I want to remove data that is older that a certain number of months.. > only full months. One approach would be to get the year, month and day as numbers from the current date. Then change the day to 1 and subtract 3 from the month (borrowing 1 from the year if necessary) and then use these numbers to build the date you want to test against. > > example: today is 11-08 and I want do delete all data that is older than > this month - 3 month i.e. i want to delete all information that is older > than Aug. 1st. > > Is there an easy way to do that ? Interval cannot be used and I cannot > just pass something like now()::date < '2003-08' > > Thanks for any help here > Alex > > > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster
On Saturday 08 November 2003 9:04 am, Alex wrote: > Hi, > I want to remove data that is older that a certain number of > months.. only full months. > > example: today is 11-08 and I want do delete all data that is older > than this month - 3 month i.e. i want to delete all information > that is older than Aug. 1st. select date_trunc('month', now()) - '3 months'::interval; ?column? ------------------------ 2003-08-01 00:00:00-07 Cheers, Steve