Effect of using operator '-' with dates in vb6
Recently I encountered a problem of handling dates while converting a vb6 code to .net code.
Problem - cant predict what the output of (date1 - date2 ) would yield in vb6
Solution - vb6 stores dates as doubles so if we use an arithmetic operator such as '-' and '+', the result would be in double which then will be converted to date. so in order to replicate something like this in .net please try the following code:
Dim i As Date, k As Double, j As Date
Problem - cant predict what the output of (date1 - date2 ) would yield in vb6
Solution - vb6 stores dates as doubles so if we use an arithmetic operator such as '-' and '+', the result would be in double which then will be converted to date. so in order to replicate something like this in .net please try the following code:
Dim i As Date, k As Double, j As Date
i = "01/01/2000"
k = 23 / 12 - CDbl(i.ToOADate())
j = CDate(Date.FromOADate(k))
It is better if we use all the date functions such as datediff, dateadd while dealing with dates in vb.net however if we want to replicate the above behavior we can definitely use above code snippet.
It is better if we use all the date functions such as datediff, dateadd while dealing with dates in vb.net however if we want to replicate the above behavior we can definitely use above code snippet.
Comments
Post a Comment