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

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

@Anelisa_Bolosha1

As per error inceptiondate is empty cna you try to print and check if it is empty

cheers


I want to convert this date format returned by ‘inceptiondate’ on the message box to a date format : dd/MM/yyyy

@Anelisa_Bolosha1

As per message box this is what you need to use

inceptiondt2 = Datetime.ParseExact(inceptiondate,"MM/dd/yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")

cheers

1 Like

Error is gone now but is it possible to have it in this format: dd/MM/yyyy

@Anelisa_Bolosha1

This is how you need to change

inceptiondt2 = Datetime.ParseExact(inceptiondate,"MM/dd/yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture).ToString("/dd/MM/yyyy")

basically need to change value inside tostring as you need

Hope this helps and clears your issue

cheers

Oh no I changed it ,it worked thank you all for your assistance…

Cheers

1 Like

Now I see and understand, thank you lots :blush: :saluting_face:

1 Like

Happy Automation :slight_smile:

cheers

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