Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting DateAdd and Format code from VB6 to C#

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.

like image 242
eric_13 Avatar asked Jun 26 '12 13:06

eric_13


People also ask

How do I add days to a date in VB6?

Format converts this date to a String (well to a Variant containing a String to be precise), but DateAdd needs a Date parameter in order to be able to add days. DateAdd is declared like this: Instead of giving a warning or a compiler error, VB6 silently converts this string back to a Date and passes it to DateAdd.

Can I convert from VB to C?

@ cpallini. Can you kindly share me the link for converting from VB to C. I can also resolve the bugs after conversion. There is no link to share. Converting VB to C is feasible, however you must know both the languages.

How do I convert a date to a string in SQL?

If you get your date from a recordset, you can store it in a date variable and just call the following formatting function to get the string representation you like: Then you can pass this value to your SQL query along with the proper date delimiters. (if not using parameters)

Can gdateformat contain only month and year?

or DateTime.Today in .NET (C# or VB.NET). But gDATEFORMAT could contain only month and year. VB6 (using my Swiss locale):


1 Answers

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);
like image 185
Steven Doggart Avatar answered Sep 17 '22 08:09

Steven Doggart