Date and excel


#1

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.


#2

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

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


#3

@qaz1 try below one

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


#4

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”)


#5

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

Try once like above.


#6

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


#7

@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


#8

Hi @qaz1, Try using the below one.

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


#9

@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


#10

@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.


#11

It works now… Thank you :slight_smile: