Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count paydays left in year

I want to count the number of days that

  1. Occur between now and the end of the year (i.e 31 December), and
  2. That fall on either the 15th or last day of the month (30th for April, June, September, November; 31st for January, March, May, July, August, October, December; 28th for February).

Is there a way to accomplish this?

like image 788
Anna Lam Avatar asked Aug 08 '12 00:08

Anna Lam


1 Answers

This seems like it might work (though I think it could likely be tidied up and I'm sure there's a better way...)

=(12-MONTH(TODAY()))*2 
+ IF(DAY(TODAY())<15,2,
        IF(DAY(TODAY())<DAY(DATE(YEAR(TODAY()),MONTH(TODAY())+1,1)-1),1,0))

(12-MONTH(TODAY()))*2 : Two days for each full remaining month

Plus 2 days if before the 15th

or

Plus 1 day if 15th or later and not the last day of the current month

like image 98
Tim Williams Avatar answered Sep 30 '22 12:09

Tim Williams