Sahil_Garg
(Sahil Garg)
October 14, 2020, 7:16am
1
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
ppr
(Peter Preuss)
October 14, 2020, 7:21am
2
@Sahil_Garg
Have a Look here
@BalaM1510
the main building block is an array with formats:
[grafik]
which can be used
DateTime.ParseExact(YourDateString, arrFormats, YourCultureInfo, DateTimeStyles.None)
from your question it can be derived:
a column with date strings is the input for a dateTime.ParseExact
the conversion result will update the value within the column
LINQ could be used for this. But as we have to be prepared for conversion fails LINQ is less helfull for this due:
ALL or Nothing is converted
intran…
@gerlynn_lxy
find a reworked approach here:
FindDates_MultipleFormats_WithinDateRange.xaml (16.6 KB)
First Stage: Configure the DateFormats inside a DataTable (can be later externalized)
Second Stage: Filter out all dates that are compatible with the configured date formats
Third Stage: Create a report Datatable for all non parseable dates
Fourth Stage: do the filtering
As it is defensive, checks the possibilities of parsing and also is handling empty results the code is now more stable a…
1 Like
balupad14
(Balamurugan)
October 14, 2020, 7:22am
3
Hi @Sahil_Garg ,
Here is an activity to convert the Datatable column data type to DateTime.Maybe. It helps you.
Thank you
Balamurugan.S
Sahil_Garg
(Sahil Garg)
October 14, 2020, 7:51am
4
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
Sahil_Garg
(Sahil Garg)
October 14, 2020, 7:54am
5
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”)
ppr
(Peter Preuss)
October 14, 2020, 8:14am
7
requirement is not clear
maybe you a looking for this one:
defining a string array with the different formats:
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
Sahil_Garg
(Sahil Garg)
October 14, 2020, 8:19am
8
Thank you for the support, i am trying the way will get back with result, give me little time .
Sahil_Garg
(Sahil Garg)
October 14, 2020, 8:41am
9
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.
ppr
(Peter Preuss)
October 14, 2020, 8:49am
10
@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
ppr
(Peter Preuss)
October 14, 2020, 8:59am
12
@Sahil_Garg
ensure following
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
Sahil_Garg
(Sahil Garg)
October 14, 2020, 9:04am
13
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
Sahil_Garg
(Sahil Garg)
October 14, 2020, 10:02am
15
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 .
ppr
(Peter Preuss)
October 14, 2020, 10:05am
16
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
ppr
(Peter Preuss)
October 14, 2020, 10:50am
18
ppr:
exception while parsing?
often empty string or dates in another format can cause this
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
Sahil_Garg
(Sahil Garg)
October 14, 2020, 1:01pm
20
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