dates of month
Dheerendra
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
-
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
-
Dheerendra Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Registered Posts: 21 ✭✭✭✭
Many Thanks Zach