Assign: String was not recognized as a valid DateTime

hello sir /madam
i pick date in this format “28-Dec-2019” from excel and convert it another format but it gives me e
Assign: String was not recognized as a valid DateTime.
how can i solve this issue
regards arjun

Hi @arjun_27,

Are you using DateTime.ParseExact ?


DateTime.ParseExact(this.Text, "dd-MMM-yyyy", CultureInfo.InvariantCulture)


DateTime.ParseExact(this.Text, "dd-MMM-yyyy", null)
1 Like

What Rene said but it should be "dd-MMM-yyyy"

1 Like

be careful with your statement there, if your excel has that column formatted as date, then you should not care about any format, just use the data as DateTime…

null does not exist in it should be Nothing

i have scrape the data from pdf

humm… in your post, you say excel…

sorry but i scrape date from pdf and write in excel
regards arjun

Use DateTime.ParseExact.- Converts the specified string representation of a date and time to its C# DateTime equivalent using the specified format and culture-specific format information. The format of the string representation must match the specified format exactly. ParseExact and TryParseExact allows to use a custom format string.

DateTime date = DateTime.ParseExact(strDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);

The IFormatProvider parameter specifies the culture to use to parse the date. Unless your string comes from the user, you should pass CultureInfo.InvariantCulture. If the string does come from the user, you should pass CultureInfo.CurrentCulture, which will use the settings that the user specified in Regional Options in Control Panel.

Hello Arjun,
In this video I do a lot of stuff with String and DateTime:

0:35 Examples for Substring functions
4:10 IndexOf and LastIndexOf
5:00 SubString working together IndexOf and LastIndexOf
6:45 Split string by character
8:50 Split string by string
12:00 Lower Case and Upper Case
12:45 Trim
15:05 Compare strings in multiple ways
19:05 Resume of all the String function part
20:05 DateTime to string in multiple ways
23:00 AddDays get DayofWeek
25:40 Convert from String to DateTime
26:20 Compare DateTime

Cristian Negulescu