Hello all,
I have excel file,
Assign varDateTime = Datetime.ParseExact(in_DataTableDLV030.Rows(0)(3).ToString.SubString(0,10).Trim, “dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture)
How can I know this day (varDateTime) is the last day of the month a Sunday ?
If Sunday: varDateTime -1 day
Thank all
I want to know varDateTime is last day of month (28 of Feb, 30,31 of another month) a Sunday?
Hey @anh.nguyen ,
You can check if varDateTime.DayOfWeek.ToString.Equals("Sunday")
ppr
(Peter Preuss)
August 17, 2023, 8:16am
5
Producing a month last day samples:
Checking the Weekday:
hi @anh.nguyen
var=new datetime (now.year,now.month,datetime.daysInMonth(Now.year,Now.month))
this give you the last day
use var.dayofweek.tostring.equals(“sunday”)
Hi @anh.nguyen ,
get last day of last month
New DateTime(Now.Year,Now.Month,1).AddDays(-1).ToString(“dd/MM/yyyy”)
strDate = “Sunday”
regards,
LNV
Thank all, but I will explain more:
I will read Excel file and get date into varDateTime :
varDateTime = Datetime.ParseExact(in_DataTableDLV030.Rows(0)(3).ToString.SubString(0,10).Trim, “dd/MM/yyyy”,
System.Globalization.CultureInfo.InvariantCulture)
Then check this varDateTime is the last day of the Month a Sunday?
If Sunday: varDateTime -1day
ppr
(Peter Preuss)
August 17, 2023, 8:23am
9
varDateTime.AddDays({-1,0,0,0,0,0,0}(varDateTime.DayOfWeek))
we configured an offset array and set for the first item (sunday) an offset of 1 day back
Thank all,
I don’t want to check the last day of this month, I want to check my variable (day of Month in Excel) is the last day of the Month a Sunday?
Ex: My excel date: 30 April 2023 this is the last day of April a Sunday
ppr
(Peter Preuss)
August 17, 2023, 8:53am
11
we showcased this at least with:
ppr:
Checking the Weekday:
Sorry for my knowledge. by your code is the last day of the month fixed? how I can use my variable (from excel example .1…28,29, 30 of April) for this code?
ppr
(Peter Preuss)
August 17, 2023, 9:04am
13
use any variable which is of DataType: DateTime
myDateTimeVar.DayOfWeek = DayOfWeek.Sunday
1.check Sunday
varDateTime.DayOfWeek=DayOfWeek.Sunday
2.get last day of month
varDateTime.AddMonths(1).AddDays(-1)
–>compare 2 dates
Parvathy
(PS Parvathy)
August 17, 2023, 9:20am
16
Hi @anh.nguyen
Try this:
Read Excel File
└ Assign varDateTime = DateTime.ParseExact(in_DataTableDLV030.Rows(0)(3).ToString.Substring(0, 10).Trim, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture)(DataType: System.DateTime)
Assign isLastDayOfMonth = varDateTime.AddDays(1).Month <> varDateTime.Month(DataType: System.Boolean)
Assign isSunday = varDateTime.DayOfWeek = DayOfWeek.Sunday(DataType: System.Boolean)
If isLastDayOfMonth AndAlso isSunday
└ Assign varDateTime = varDateTime.AddDays(-1)
Hope it helps!!
1 Like
Hi @anh.nguyen
You can use the “Modify Date” activity to get the last day of the month very easily. Use the output of the activity (i.e. set it as variable “dateModified”). Then, as suggested previously already, use “dateModified.DayOfWeek” to check whether this is a Sunday.
Hope this helps!
Best regards
Roman
Thank all and @Parvathy this is the result i expected.
1 Like
system
(system)
Closed
August 20, 2023, 9:55am
20
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.