Hello everyone,
I would like to enter the date of the last month in two fields.
If today is February, I would like the robot to enter the date: 01/01/2024 in the “From” field.
In the “To” field it should then enter 31/01/2024.
My current string always does this for the current month. But I would like to have it for the last month.
Current:
New DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString(“dd/MM/yyyy”)
AND second:
New DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)).ToString(“dd/MM/yyyy”)
Kind regards,
Markus
Parvathy
(PS Parvathy)
February 1, 2024, 1:54pm
2
Hi @Markus_Reimer
Try the below syntax:
To get First date:
New DateTime(now.Year,now.Month,1).AddMonths(-1).ToString("dd/MM/yyyy")
To get last date:
str_lastdate= New DateTime(now.Year,now.Month,1).AddDays(-1).ToString("dd/MM/yyyy")
Hope it helps!!
rlgandu
(Rajyalakshmi Gandu)
February 1, 2024, 1:55pm
3
@Markus_Reimer
Assign activity:
- fromDate = New DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(-1).ToString("dd/MM/yyyy")
Assign activity:
- toDate = New DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddDays(-1).ToString("dd/MM/yyyy")
Parvathy
(PS Parvathy)
February 1, 2024, 2:00pm
4
Hi @Markus_Reimer
Hi @Markus_Reimer
Try the below syntax:
To get First date:
New DateTime(now.Year,now.Month,1).AddMonths(-1).ToString("dd/MM/yyyy")
[image]
To get last date:
str_lastdate= New DateTime(now.Year,now.Month,1).AddDays(-1).ToString("dd/MM/yyyy")
[image]
Hope it helps!!
Adding to the post
str_firstdate= New DateTime(now.Year,now.Month,1).AddMonths(-1).ToString("dd/MM/yyyy")
str_lastdate= New DateTime(now.Year,now.Month,1).AddDays(-1).ToString("dd/MM/yyyy")
str_firstdate and str_lastdate are of DataType System.String
Regards
mkankatala
(Mahesh Kankatala)
February 1, 2024, 2:01pm
5
Hi @Markus_Reimer
Check the below expression for From field,
- Assign -> FromDate = DateTime.ParseExact(Now.ToString("MMMM yyyy"),"MMMM yyyy",System.Globalization.CultureInfo.InvariantCulture).AddMonths(-1).ToString("dd/MM/yyyy")
Check the below expression for To field,
- Assign -> ToDate = DateTime.ParseExact(Now.ToString("MMMM yyyy"),"MMMM yyyy",System.Globalization.CultureInfo.InvariantCulture).AddDays(-1).ToString("dd/MM/yyyy")
Hope it helps!!
2 Likes
mkankatala
(Mahesh Kankatala)
February 1, 2024, 2:18pm
7
It’s my pleasure… @Markus_Reimer
Happy Automation!!
system
(system)
Closed
February 4, 2024, 2:18pm
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.