Date Type error, Date with year 1999 is not working but working on date with year 2000

Hi everyone, Can you please assist me here in this error:
Assign: Conversion from string “12/15/1999 00:00:00” to type ‘Date’ is not valid.

image
I have to change this date from the database in the format dd/mm/yy,


image

Use Datetime.ParseExact(inceptiondt2,“yyyy-MM-dd”,System.Globalization.CultureInfo.InvariantCulture) so you can explicitly tell it the datetime format.

image

On this one there is no error.

That’s because the last digits (01) are a valid month, but for 1999-12-15, 15 is not a valid month. Your logic has it thinking the last two digits are the month.

Where do I put it, and what do I remove?

Replace your CDate expression with the Datetime.ParseExact


throws an error

@Anelisa_Bolosha1

Please remove Cdate from the right side of assign and then use .ToString("MM/dd/yyyy")

final expression - Datetime.ParseExact(inceptiondt2,"yyyy-MM-dd",System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")

cheers

Should I use this from my original expression, if you have example please show me how

@Anelisa_Bolosha1

Use assign like below

inceptiondt2 = Datetime.ParseExact(inceptiondate,"yyyy-MM-dd",System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")

cheers

No, replace the entire CDate expression with the Datetime.ParseExact I gave you. Don’t put the Datetime.ParseExact inside the CDate.


It throws this error

Jep, I did it threw an error

@Anelisa_Bolosha1

As per error we can see that inceptiondate is emty…did you assign currentrow("Column").ToString to it?

cheers

The date on the database is displayed like this:
image

I want it in the format:
image


I assigned it like this

If inceptiondt2 is a string you can’t assign a datetime to it.

What are you trying to do here? CDate and Datetime.Parse return datetime values, not string. Adding .ToString on the end converts it to a date. Also, you don’t assign to System.Globalization and don’t have to assign to inceptiondate that’s just extra unnecessary work. If you’re trying to get a datetime value into inceptiondt2 then use…

assign inceptiondt2 = Datetime.ParseExact(DT_Connect.Rows(0)(“CommencemendtDate”).ToString,“yyyy-MM-dd”,System.Globilization.CultureInfo.InvariantCulture)

If inceptiondt2 is string and that’s what you want, then add .ToString(format) onto the end of that.

Also, DT_Connect.Rows(0) will only give you the value that’s in the first row of the datatable. Is that what you want or are you trying to do the conversion to multiple rows? Are you trying to assign the modified value back to the datatable?

Hi @Anelisa_Bolosha1 ,

Could also check with the below post on recognising the formats of the date (as sometimes the date format from Excel and Datatable differs) and using the appropriate date format after the analysis is done :