dates of month

Options
dhyadav79
dhyadav79 Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Registered Posts: 21 ✭✭✭✭

Hi,

I want to get first and last date of month on basis of current date.

Could you please help.

Answers

  • Zach
    Zach Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer, Registered Posts: 153 Dataiker
    edited July 17
    Options

    Hi @dhyadav79
    ,

    Where were you trying to get the first and last date?

    If you're trying to do it using a Formula, you can do it like this:

    Get the first day of the month:

    trunc(now(), "months")

    Get the last day of the month:

    inc(trunc(inc(now(), 1, "months"), "months"), -1, "days")

    If you're trying to do it using Python, you can use the following code:

    import calendar
    import datetime
    
    today = datetime.date.today()
    month_range = calendar.monthrange(today.year, today.month)
    
    first_day = today.replace(day=1)
    last_day = today.replace(day=month_range[1])
    
    print(f"Today: {today}, First day: {first_day}, Last day: {last_day}")

    Thanks,

    Zach

  • dhyadav79
    dhyadav79 Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Registered Posts: 21 ✭✭✭✭
    Options

    Many Thanks Zach

Setup Info
    Tags
      Help me…