String.format issue

Hi Team,

I am giving the below syntax.

String.Format(Now.AddDays({0}).Tostring(“dd-MM-yyyy”),str_backdate)

But its throwing an error.

Here I want to replace the value {0} with str_backdate which is -1.

Thanks!

Hi @satish_kumar
Try this:

str_backdate="-1"
formattedDate= String.Format(DateTime.Now.AddDays(Convert.ToDouble(str_backdate)).ToString("dd-MM-yyyy"))

Note: Both str_backdate and formattedDate are of Datatype System.String
Refer the below image for better understanding.

Hope it helps!!

1 Like

Hi @satish_kumar

AddDays is expecting an Int / double, so you are getting this error

No need of String format but you have to convert the string to cdbl

image

Hope this resolves your issue

Thanks,
Srini

If you find solution for your query please mark it as solution to close the loop. @satish_kumar

Happy Automation

Regards,

Hi @satish_kumar

You can simply try this

String.Format(Now.AddDays(Convert.ToDouble(str_BackDate)).ToString("dd-MM-yyyy"))

I hope it helps!!

You can’t use String.Format to replace in something that’s not a string.

Just do…

Now.AddDays(DateInterval.Day,CInt(str_backdate)).Tostring(“dd-MM-yyyy”)

@satish_kumar

Try this

String.Format(Now.AddDays(Cint({0})).Tostring("dd-MM-yyyy"),str_backdate)

You just need to convert string to integer as needed

Cheers