Check if an excel cell is formatted as a date

Hi, i need help with what VB expression should i use if i’d like to:

  • check if an excel cell is formatted as a date (dd/mm/yyyy hh:mm AM/PM) format.

Am intending to use this expression inside an IF statement.

IF a cell is not formatted as a date… THEN… (format it as date)
ELSE… (ignore)

Thanks in advance!

Hi @ctkoh
DateTime.TryParseExact(strinput.ToString,“MM/dd/yyyy hh:mm:ss”, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, Nothing)
Inside if use this condition if it is true then leave it otherwise in else section.

Hi @ctkoh

To be exact with your format.please use this

DateTime.TryParseExact((“Excel date string”, “dd/MM/yyyy hh:mm tt”, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, Nothing)

And for formatting you can use format cell

Cheers

Hi! Thank you for the fast reply!

Just wondering how do I use this VB expression to check a specific cell in my xlsx file.

I don’t see it referencing any excel file or cell.

@ctkoh

Use for each row in excel then get the value and use the value in place of string

Currentrow("datecolumn").tostring.trim inside loop this is how you get the date string

Cheers

For each row in datatable inside currentrow(index of column).tostring will be you input string in the above code

Thank you so much for the quick advice everyone!

With your help i managed to get the solution. :slight_smile: