Hello,
I have a string as 1012022 in my excel sheet and I want to convert this into date time format.
Date.ParseExact(RegRow(“DAY”).Tostring.Trim,“dMMyyyy”,System.Globalization.CultureInfo.InvariantCulture)
where Day=“1012022”
I had tried date parsing and convert.datetime methods but they didn’t worked.
Could any one please help me on this.
Thanks in advance.
HI @Sirimalla_Karthik_Chandra
Check with the below expression below would be the Expression!
DateTime.ParseExact(RegRow(“DAY”).Tostring.Substring(0,7),“dMMyyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“dd-MM-yyyy”)
If the above not working share the Column Printing Using the write line
Regards
Yoichi
(Yoichi)
December 23, 2021, 7:08am
3
Hi,
Can you try the following expression?
DateTime.ParseExact(RegRow("DAY").Tostring.Trim.PadLeft(8, "0"c),"ddMMyyyy",System.Globalization.CultureInfo.InvariantCulture)
Regards,
arivu96
(Arivazhagan A)
December 23, 2021, 7:10am
4
Hi @Sirimalla_Karthik_Chandra ,
TRY BELO CODE
DateTime.ParseExact("1012022","ddMyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("dd-MM-yy")
Regards,
Arivu
Jobin_Joy
(Jobin Thekkekara Joy)
December 23, 2021, 9:14am
5
Hi @Sirimalla_Karthik_Chandra
It will work with either Date.ParseExact/DateTime.ParseExact
Thank you.
Hi @Jobin_Joy , thanks for replying to my query.
The String “1012022” should refer to the date 01-01-2022.
Hi @arivu96 thanks for replying. The String “1012022” should refer to the date 01-01-2022.
Hi @Yoichi , Thanks man for helping me out. Your Expression is working for me.
Jobin_Joy
(Jobin Thekkekara Joy)
December 25, 2021, 4:26pm
9
Hi @Sirimalla_Karthik_Chandra
This technically an incorrect date format. Is there any specific reason for this format?
Because in some point of time the above format will fail.
ex: 11th Dec 2021 → (11122021)how will you indicate this date in the above format? (dMMyyyy)
single digit day is not sufficient right.
Thank you.
I accept your point that the date format is technically incorrect. I only get dates from 1 to 9 in single digit followed by month and year. However After 9 the dates are generated in standard format that is in “10012022”, Hence I’m not facing any issues for dates in between “10” to “31” while date parsing.
The above expression provided by @Yoichi is working fine for me.
Thank you so much @Jobin_Joy for replying to my query and helping me as much as possible.