Hello,
How can I convert “18 mai 2020 16:15:44” as String to Date ?
Thanks
Hello,
How can I convert “18 mai 2020 16:15:44” as String to Date ?
Thanks
with the assumption that the lower case written mai comes from a french local have a look here:
DateTime.ParseExact("18 mai 2020 16:15:44","dd MMM yyyy HH:mm:ss",CultureInfo.CreateSpecificCulture("fr-FR"))
feel free to change to another culture if needed
ensure following:
Thank you for your help, it works fine. But please can you show me how to display it on this format please ?
18/05/2020
Thank you in advance !
give a try on following:
DateTime.ParseExact(“18 mai 2020 16:15:44”,“dd MMM yyyy HH:mm:ss”,CultureInfo.CreateSpecificCulture(“fr-FR”)).toString(“dd/MM/yyyy”)
Hi, it worked fine, until i found an other issue, sometimes dates are as this format “3 juin 2020 09:49:50”, do you have any idea how can manage this type too please ?
Thank you
Hello @ppr
I found this solution, but can’t figure out how you use it ?
myString = DateTime.ParseExact(myString, arrFormat,CultureInfo.CreateSpecificCulture(“fr-FR”)).toString(“dd/MM/yyyy”)
Can you explain please ?
@maroua301
lets assume the processed data comes formated within different formats like 01 juin 2020 or 01.06.2020 then we can handle this for parsing the date
just use the code from above and ensure that the used string array “arrFormat” contains the different format patterns. Does mean:
have a variable in scope: arrFormat, DataType: String(),
for the example: 01 juin 2020 or 01.06.2020 the content of the array would be:
{dd MMMM yyyy, dd.MM.yyyy}
@ppr
It’s what i did, but i have an error…
you missed out the 4th parameter:
DateTime.ParseExact(YourDateString, arrFormats, YourCultureInfo, DateTimeStyles.None)
I don’t get what you want me to do, can you please correct me this ?
test.xaml (6.0 KB)
Change your code to following:
DateTime.ParseExact(varString, arrArray, CultureInfo.CreateSpecificCulture(“fr-FR”), DateTimeStyles.None )
the ParseExact Method requires these 4 arguments in case you want to work with string array expressing the different date formats
I unterstand now, thank you for your help and kindess !
In case others have the same issue, here’s an example :
DateTime.ParseExact(varString, varArray, CultureInfo.CreateSpecificCulture(“fr-FR”), DateTimeStyles.None).toString(“dd/MM/yyyy”)
Cheers
Based on your examples,
18 mai 2020 16:15:44
3 juin 2020 09:49:50
I believe you need only one date format.
d MMM yyyy HH:mm:ss
It is almost the same as ppr suggested with the only difference that uses d instead of dd
You can use this article to learn more: DateTime Format In C#
If the requirements are different, you can also use an array of date formats as you have already
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.