Atwp67
Atwp67

Reputation: 307

Stuck on dates using interval

A little stuck, the end user is allowed to pick a year/month and then collect the data going back 5 months. I'm good with setting the initial date off a timestamp (yyyy-mm-dd hh:mm:ss) column but can I use last_day in conjunction with interval. So if the end user picks May 2013 they can collect all the data from May 31, 2013 through January 1, 2013.

 Ex. set @d2:=concat('2013-05','-01');
     set @d1:=@d2 - last_day(interval 5 month);
     select @d1,@d2;

Any help/guidance is much appreciated.

Upvotes: 0

Views: 41

Answers (1)

Toote
Toote

Reputation: 3413

The function LAST_DAY takes a date as an argument, not an interval.

It would appear that the code you want is:

set @d1 := LAST_DAY(@d2 - INTERVAL 5 MONTH) 

Upvotes: 1

Related Questions