Check if a date is in a current month

Hi all,

I have a set of dates

1/1/2023
2/1/2023
3/1/2023

in MM/dd/yyyy.

I want to put a condition in which the date which belongs to current month is taken.

Thank you

@Yugal_Raju

Now.Month gives the current month…If the dates are in Datatble then use filter datatable with satrts with

Now.ToString(“M”) + “/” on the date column

Now.Month also can be used

cheers

Can you please explain i didn’t understand fully.

Hi @Yugal_Raju ,

Use Assign dayVar = Datetime.ParseExact(“02-30-2023”,“MM-dd-yyyy”,System.Globalization.CultureInfo.InvariantCulture).Day Inside a try catch block.

An exception will be thrown if Date passed doesn’t follows, for e.g., 02-30-2023 no 30th Feb.
You can perform actions in catch block if Day is not in that Month.

@Yugal_Raju

Now.Month or Now.ToString(“M”) will give the month of current date

Now to use that as filter if the data is in datatable use filter datatable activity with this filter

Or from the date you have you can extract the month as well using

Datetime.parse(“Yourdate”).ToString(“M”) then these can be compared

Hope this helps

cheers

In your date formate, use “MM/dd/yyyy” instead of “MM-dd-yyyy”.

HI @Yugal_Raju

Lets say you have dates in the array or list

Checkout this

variable1.AsEnumerable().Where(Function(s) DateTime.ParseExact(s.ToString,{"MM/dd/yyyy","M/d/yyyy"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).Month=Now.Month).Select(Function(a) a.ToString)

If it is the set of dates in the datatable column

dt1.AsEnumerable().Where(Function(s) DateTime.ParseExact(s(0).ToString,{"MM/dd/yyyy","M/d/yyyy"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).Month=Now.Month).CopyToDataTable

Regards
Sudharsan