sql - How to calculate the broadcast year and month out of the given date? -


is there way calculate the broadcast year , month given gregorian date?

the advertising broadcast calendar differs regular calendar, in way every month needs start on monday , end on sunday , have 4 or 5 weeks. can read here: http://en.wikipedia.org/wiki/broadcast_calendar

this pretty common thing in tv advertising, guess there standard mathematical formula it, uses combination of date functions (week(), month(), etc...).

here example mapping between gregorian , broadcast dates:

| gregorian_date | broadcast_month | broadcast_year | +----------------+-----------------+----------------+ |   2014-12-27   |       12        |     2014       | |   2014-12-28   |       12        |     2014       | |   2014-12-29   |        1        |     2015       | |   2014-12-30   |        1        |     2015       | |   2014-12-31   |        1        |     2015       | |   2015-01-01   |        1        |     2015       | |   2015-01-02   |        1        |     2015       | 

here example how broadcast calendar looks 2015: http://www.rab.com/public/reports/broadcastcalendar_2015.pdf

as far can see, pattern first of gregorian month falls within first week of broadcast calendar, , days previous month pulled forward month create full weeks. in excel, can use following formula in cell b2 (first of broadcast months above) calculate broadcast month:

=month(a2+(7-weekday(a2,2))) 

similarly, in cell c2:

=if(and(month(a2)=12,b2=1),year(a2)+1,year(a2)) 

this return broadcast month , year dates put data set.

hope helps!


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -