I thought about your problem, and there is an aspect that I missed yesterday. I thought the Format function didn't make sense, but even if it looks weird, it might make sense. Let me explain.
In VB6 we have
tAvailableDate = DateAdd("d", 21, Format(Now, gDATEFORMAT))
Why does this look weird (or even wrong)? Now is a Date . Format converts this date to String (well, a Variant containing a String , to be precise), but DateAdd needs the Date parameter to be able to add days. DateAdd declared as follows:
Function DateAdd(Interval As String, Number As Double, Date)
Instead of giving a warning or compiler error, VB6 silently converts this string back to Date and passes it to DateAdd . Therefore, my first assumption was to simply abandon this Format .
BUT this Format may have the desired effect on the result, depending on how gDATEFORMAT determined. If gDATEFORMAT contains only a part of the date, the format function will lose some of the time! However, this can simply be achieved using the Date function instead of using the Now function in VB6
tAvailableDate = DateAdd("d", 21, Date)
or DateTime.Today in .NET (C # or VB.NET).
But gDATEFORMAT can only contain a month and a year. VB6 (using my Swiss language):
Date ==> 27.06.2012 Format(Date,"MM.yyyy") ==> "06.2012" CDate(Format(Date,"MM.yyyy")) ==> 01.06.2012
As you can see, formatting the date will return the first day of the current month in this case. By adding 21 days, you will always receive the 22nd day of the current month. This is completely different than adding 21 days to the current date! In C #, you can achieve the same result with
DateTime today = DateTime.Today; tAvailableDate = new DateTime(today.Year, today.Month, 22);
To decide which approach is right, you must either know what gDATEFORMAT contains, or if it is a variable, format the date and then parse the resulting string to get the date again.