Friday, 24 May 2013

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

  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.

No comments:

Post a Comment

SSIS Issues : A Day of Learning

Seldom are the days when you run into complex issues but resolve them in the shortest interval of time. Thanks to Larry Page and my fello...