Last day of the month a Sunday?

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")

Producing a month last day samples:
grafik

Checking the Weekday:
grafik

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 :
image
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

grafik
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
image

we showcased this at least with:

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?

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

Hi @anh.nguyen ,

Workflow

dateList

Enumerable.Range(1,12).ToArray().Select(Function(x) New DateTime(cdate(""+x.tostring+"/01/2023").Year, cdate(""+x.tostring+"/01/2023").Month, DateTime.DaysInMonth(cdate(""+x.tostring+"/01/2023").Year, cdate(""+x.tostring+"/01/2023").Month))).toarray().Where(Function(x) x.DayOfWeek=DayOfWeek.Sunday).ToArray()

Thanks,

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

Thank you @anh.nguyen

Happy Automation

Regards,

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.