Elya
April 23, 2019, 11:17am
1
Hi guys,
I’ve some issues with ParseExact. When I try to insert a array of string instead a string for my format that doesn’t work
This format work at this moment: datetime.ParseExact(mydate,“dd/MM/yyyy”,Nothing)
So i just want to remplace “dd/MM/yyyy” by a array of string like {“MM/dd/yyyy”,“M/d/yyyy”}
— From .net documentation: ParseExact(String, String , IFormatProvider, DateTimeStyles)
1 Like
Hi @Elya
Do you want to enter the date in a specific format like {“MM/dd/yyyy”} or any other format.
Did i understand your issue correctly…?
If so use like this
Datetime.ToString(“MM/dd/yyyy”) or
Datetime.ToString(“M/d/yyyy”) or any format you want, but within tostring()
As you say you pass by array with different format, you can pass that as a string within this ToString() all inside a for each loop.
Cheers.
2 Likes
Hello @Elya you can not pass String to DateTIme.Parse method. There can be work around but its all depends on you processing steps…
we can give you DateTimeObject … but you may or may not need it…
let us know why you want to parse string to datetime objects
what will be your next processing steps etc.
string strDate = "04/23/2019";
string[] arr = {"MM/dd/yyyy","M/d/yyyy"};
DateTime dt = DateTime.ParseExact(strDate, arr, new CultureInfo("en-US"),
DateTimeStyles.None);
Console.WriteLine(dt.ToShortDateString());
The sample C# code works for me.
You must initialize the culture info object. Then only the array of formats will be considered and works.
Regards,
Karthik Byggari
8 Likes
Elya
April 23, 2019, 12:31pm
5
yeah that way is possible but not really clean instead to use one command
1 Like
Elya
April 23, 2019, 12:32pm
6
1 Like
system
(system)
Closed
April 26, 2019, 12:32pm
7
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.