Trying to convert it to 24 hrs Format using below;
Datetime.ParseExact(dateError,“dd/MM/yyyy hh:mm:ss tt”,new system.Globalization.CultureInfo(“en-US”)).ToString(“yyyy-MM-dd HH:mm:ss”)
But i am getting error as “String was not recognized as a valid DateTime.”
You had:
Datetime.ParseExact(dateError,“dd/MM/yyyy hh:mm:ss tt”,New system.Globalization.CultureInfo(“en-US”)).ToString(“yyyy-MM-dd HH:mm:ss”)
So either use one of these:
Date.Parse(dateError).ToString(“MM/dd/yyyy HH:mm:ss”) + Environment.NewLine +
Datetime.ParseExact(dateError,“dd/MM/yyyy h:mm:ss tt”,New system.Globalization.CultureInfo(“en-US”)).ToString(“yyyy-MM-dd HH:mm:ss”)
Pretty much what @prasath17 said. hh:mm:ss tt must be h:mm:ss tt
That day it worked for the below senario;
strStartDate - “06/17/2021 3:30:00 AM”
Convert.ToDateTime(Date.Parse(strStartDate).ToString(“MM/dd/yyyy HH:mm:ss”))
but now i have value which i am getting from excel;
strExcelValue = “17/06/2021”
Convert.ToDateTime(Date.Parse(“17/06/2021”).ToString(“dd/MM/yyyy”))
Its again giving error as “Assign: String was not recognized as a valid DateTime.”
Are you using “Preserve Format” in the read range??
Remember, Date.parse takes your local setting(Time). Say if your system date format is MM/dd/yyyy and if you using dd/MM/yyyy to parse it, it will fail…Please check below…
Yes, the system format is MM/dd/yyyy.
But then i have the value from excel as text which is dd/MM/yyyy.
so i need to check if today’s date falls in between date1 and date2.
date1,date2 are taken from excel as text.
Ex.: date1 = “14/06/2021” and date2 = “20/06/2021”.
then need to check if today’s date falls between these 2 dates or not.