Survey banner
The Dataiku Community is moving to a new home! Some short term disruption starting next week: LEARN MORE

dates of month

dhyadav79
Level 2
dates of month

Hi,

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

Could you please help.

 

0 Kudos
2 Replies
ZachM
Dataiker

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

0 Kudos
dhyadav79
Level 2
Author

Many Thanks Zach

0 Kudos