How to give condition for Date Formats

Dear Forum Members,

I have different datatables with different format of dates for example,
Some have 12/02/2020 , Some have 12-02-2020.

I just want to take month from dates.

But did not getting what condition should i give for different formats.

Getting month from single format but getting error if i use same for other format .

Any suggestion, any help will be appreciated.

Thanks and Regards
Sahil Garg

@Sahil_Garg
Have a Look here

1 Like

Hi @Sahil_Garg,

Here is an activity to convert the Datatable column data type to DateTime.Maybe. It helps you.

Thank you
Balamurugan.S

Hi mate,

As per the things which i got understood from your post , they are used to convert date formats.

I want an condition like that:

If(date = 12/02/2020 or date = 12-02-2020)
{
give me monthe from date.
}

I hope you got, what i am trying to say

But let me try using your solution also . I will see, if it helps me

Thanks and regards
Sahil Garg

Hello sir,

Can’t we do something, using inbuilt package ?

Thanks and regards
Sahil Garg

DateTime.ParseExact(Convert.ToDateTime(“12/02/2020”).Date.ToString(“dd/MM/yyyy”), “dd/MM/yyyy”, Nothing).ToString(“MM”)

DateTime.ParseExact(Convert.ToDateTime(“12-02-2020”).Date.ToString(“dd-MM-yyyy”), “dd-MM-yyyy”, Nothing).ToString(“MM”)

requirement is not clear

maybe you a looking for this one:
defining a string array with the different formats:
grafik

handling different formats for the compare within the parse statement:

As it is also used in the provided demos, have a look there as well

Thank you for the support, i am trying the way will get back with result, give me little time .

Mate, as per my understanding and tryings of your way , i am not getting the desired result.

See ,
A data table with a date column will be input .Data table can be multiple not specific.
I have to get month from that Date column .

Problem is that , i am getting month properly if date format is 12/02/2020.
But getting problem if format is different like 12-02-2020.

I hope you got understand.

@Sahil_Garg
as in the demo and also in the screenshots showcased was the handling of different formats in one parse statement.

i am not getting the desired result.

have you configured the formats array properly. What is failling? We would need more info. Maybe you can share the xaml or some screenshots

Thanks

Please see ,
1.

@Sahil_Garg
ensure following
grafik

And also rework on the variable YourCultureInfo. It looks like a copy & paste that is not properly handled e.g. by variable declaration, renaming, initialization

I am getting this,

Can you share a workflow with demo 2 data tables containing 2 different format dates.
and convert it in single format

Please if it is possible

have a look above

Thanks Mate , it worked.

Can you tell me for some data table , it is showing exception of Date to String.

Anyways, Thanks for your help .

please share always enough information with us, that we can better inspect the issue.

exception of Date to String
validation issue? so just share screenshot

exception while parsing?

  • often empty string or dates in another format can cause this

Please see,

this exception comes from a string, that is empty or not in the expected format

have a look here:
FilterDates_NonValidDateFormat.xaml (8.0 KB)

this demo filters out such cases and you will get a result datatable with all non valid date format rows

Thanks :slight_smile:

Hi,
Sorry to disturb

I am getting months from nearly all files using your methods, but only this one is creating problem.
Can you get month from this excel using your method
Chiacon India.xlsx (10.9 KB)

Again, sorry to disturb you.

Thanks and regards
Sahil garg