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.
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.
@ 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.
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)
or DateTime.Today in .NET (C# or VB.NET). But gDATEFORMAT could contain only month and year. VB6 (using my Swiss locale):
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With