Converting DateAdd and Format code from VB6 to C#

eric_13 picture eric_13 · Jun 26, 2012 · Viewed 11.7k times · Source

I have the following code in vb -

tAvailableDate = DateAdd("d", 21, Format(Now, gDATEFORMAT))

I am attempting to convert this into C#.

I have converted this so far -

tAvailableDate = DateAdd("d", 21, Format (DateTime.Now, Global.gDATEFORMAT));

But I cannot find a replacement for the DateAdd() or Format() feature.

Any ideas? Thanks.

Answer

Steven Doggart picture Steven Doggart · Jun 26, 2012

DateAdd is an old VB6 method that was carried over into VB.NET for backwards compatibility. You could get it to work in C# as well if you included the Microsoft.VisualBasic namespace in your C# project, but I wouldn't recommend using the method in C# or VB.NET. Here's how you should be doing it (it's easier to read too):

tAvailableDate = DateTime.Now.AddDays(21);