Date and excel

I have extracted the date from excel and the format is “MM/dd/yyyy”

so i used
Date.ParseExact(“MM/dd/yyyy”,row(“Project Date”).ToString, System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)
to change the format to “dd/MM/yyyy”

I still face error after typing this into the message box…

Main has thrown an exception

Message: String was not recognized as a valid DateTime.

your method is date.parseExact(format, String, culture)

it should be: date.parseExact(String, format, culture)

@qaz1 try below one

Date.ParseExact(row(“Project Date”).ToString,“MM/dd/yyyy”,Nothing).ToString(“dd/MM/yyyy”)

Hi @Manjuts90, How can I change ‘03 Sep 2018’ to 9/03/2018?
It isn’t working
Date.ParseExact(dateu,“dd/MMM/yyyy”,Nothing).ToString(“M/dd/yyyy”)

@sangasangasanga Instead of dd/MMM/yyyy give dd MMM yyyy

Try once like above.

Hi @Manjuts90 , I tried like you suggested.
Date.ParseExact(dateu,“dd MMM yyyy”,Nothing).ToString(“M/dd/yyyy”)
But still got error. String was not recognized as a valid datetime

@sangasangasanga

I just tried above date with below statement, it is working fine, where dateu i am declared as string.

Please check once what value dateu variable contains

Hi @qaz1, Try using the below one.

Convert.ToDateTime(row(“Project Date”).ToString).ToString(“dd/MM/yyyy”)

@Manjuts90 Weird, it is not working for me…
dateu = Date.ParseExact(dateu,“dd MMM yyyy”,Nothing).ToString(“M/dd/yyyy”)
image

Is it because I add 2018 to it?
dateu + " 2018"
Then, I assigned the code

@sangasangasanga Don’t know what exactly problem with that. Try something like below.

Convert.ToDateTime(dateu).ToString(“dd/MM/yyyy”)

Try also Prase method and other methods u already know.

1 Like

It works now… Thank you :slight_smile:

1 Like