How to Validate the given date to YYMMDD and type that date in application

In input excel given date validate if any mismatches or
extra digits given case : 20180156 ----------- how to handle this in code

Hi @Deepthi_Borra

Please browse our Forum for the keywords such as:

  • DateTime.Parse
  • DateTime to String
  • and similar

Depending on your requirements, it is possible to shape the datetime variable however you want :slight_smile: You will have to provide more context though.

In my application Date format accepting as> YYMMDD
We are getting the Input date from excel
Suppose if i am giving the format like YYYYMMDD or DDMMYYYY or any other cases

How can i convert all those cases to applicaton accept format - YYMMDD
is CDate will work or datePrase only

Assign: String was not recognized as a valid DateTime.
got this error

I recommend to always check that it’s in a date format before conversion. To do that, simply use similar syntax with DateTime.TryParseExact() with an IF. That way, you can also throw a businessruleexception if the data is not in the correct format, or handle the data/file in the way you require for the user.

Also, if it’s possible for multiple date formats, you can use an Array of formats. So, instead of "d/M/yyyy", you can use {"d/M/yyyy","dd/MM/yyyy"}

Hope that helps.


One more thing… your date string has the wrong slash marks, so check that :smiley:

removed “/” and tryed like this but showing below error

Arr_of_strrr(array of string) =


DateTime.ParseExact(row(“Req del dt”).ToString,Arr_of_strrr,Globalization.CultureInfo.CurrentUICulture.DateTimeFormat,nothing).ToString(“yyMMdd”)

You show your argument is of type DateTime for out_Reqdl_date. Is this true? That means you must leave off the .ToString(“yyMMdd”) on the end, so it stays in the datetime type.

Usually you want to move around dates in the datetime type anyway, but if you do want to move it around in as a String type, then you will need to change the argument type to a String.

Note: anytime you see "implicit conversions from <typeA> to <typeB> error message, then it’s always something to do with having a value in the wrong type.

Hope that answers your question.


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.