Data360 Analyze

 View Only
  • 1.  End of month

    Posted 11 days ago

    Hey Brain trust

    I am struggling with how to calculate the end of the month date from a given date col e.g

    Given date col

    date

    2024-12-15

    Calculated eom col

    eom

    2014-12-31

    Appreciate if the code can be in brainscript and python please



    ------------------------------
    Abi Chaudhuri
    Senior Commercial Capability Analyst
    Telstra Corporation Limited
    Melbourne VIC
    ------------------------------


  • 2.  RE: End of month

    Posted 11 days ago

    Try this, unfortunately python 2.7 doesn't have a timedelta with months.

    Test it a bit though.



    ------------------------------
    Peter Sykes
    Data Governance & Architecture
    Vontobel Holding AG
    Zurich
    ------------------------------



  • 3.  RE: End of month

    Posted 11 days ago

    I've used this. Peter's way looks to work too, the only difference I see is you don't need to import calendar but really they both do the same thing.

    def last_day_of_month(any_day):
        # this will never fail
        # get close to the end of the month for any day, and add 4 days 'over'
        next_month = any_day.replace(day=28) + datetime.timedelta(days=4)
        # subtract the number of remaining 'overage' days to get last day of current month, or said programattically said, the previous day of the first of next month
        return next_month - datetime.timedelta(days=next_month.day)