Cannot format the value Datetime in Generic value type

I have a variable that store Date in Generic value. and now i want to format the variable in this format yyyy/MM/dd instead of dd/MM/yyyy.

eg: strAppDate in Generic Value store Date (09/03/2022)

when i run the script, i keep hit error “Cannot convert Generic Value to System.Date.Time”

Do i need to change type of variable for strAppDate?

try this

dateTime.ParseExact(genericVal.ToString, "dd/MM/yyyy",nothing).ToString("yyyy/MM/dd")


but where can i put this variable strAppDate. since this variable store the value that need to be format

@user123mem do this

strAppDate = new genericValue(dateTime.ParseExact(strAppDate.ToString, "dd/MM/yyyy",nothing).ToString("yyyy/MM/dd"))

its working now ! thanks

1 Like

The real question is why are you using a Generic Value variable?

i read some of the forum here, they using Generic value variable , so i just give it a try

It’s much better to be specific about your datatypes. I’ve never had any reason to use Generic Value.

1 Like

You could also try

CDate(YourVariable).ToString(“Format you want”)

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