List:General Discussion« Previous MessageNext Message »
From:Dan Nelson Date:October 17 2008 9:06pm
Subject:Re: FLOOR(DATE_ADD(CURDATE(), INTERVAL 4 MONTH)) -- ?
View as plain text  
In the last episode (Oct 17), Rene Fournier said:
> Okay, I realize that query won't work, but that's essentially want I  
> want to do:
> 
> Add four months to the current date, then return the first day of that  
> month, e.g.:
> 
> 	floor ( 2008-10-16 + 4 months ) = 2009-02-1

Since you know the first day of the month is always 01, this would work:

select cast(date_format(curdate() + interval 4 month,"%Y-%m-01") as date)

You can drop the cast if you're going to print the result directly, or
if you're going to plug it into a date column (mysql will do the cast
automatically)

-- 
	Dan Nelson
	dnelson@stripped
Thread
FLOOR(DATE_ADD(CURDATE(), INTERVAL 4 MONTH)) -- ?Rene Fournier17 Oct
  • Re: FLOOR(DATE_ADD(CURDATE(), INTERVAL 4 MONTH)) -- ?Rob Wultsch17 Oct
    • Re: FLOOR(DATE_ADD(CURDATE(), INTERVAL 4 MONTH)) -- ?Ian Christian17 Oct
      • Re: FLOOR(DATE_ADD(CURDATE(), INTERVAL 4 MONTH)) -- ?Rob Wultsch17 Oct
        • Re: FLOOR(DATE_ADD(CURDATE(), INTERVAL 4 MONTH)) -- ?Rob Wultsch17 Oct
  • Re: FLOOR(DATE_ADD(CURDATE(), INTERVAL 4 MONTH)) -- ?Dan Nelson17 Oct