CO2 Software
CO2 Software

Reputation: 55

If 1 is a specific date, how can I convert back and forth between date and integer in VB.NET?

I've seen varying discussions on here on converting between different date formats; what I'm curious on how to do in VB.Net is convert between integer and date and back again.

So for example, if 1 is 01/10/1990 and 9 is 09/10/1990; how would I convert back and forth on wider ranges in VB.Net?

My example dates are purely hypothetical, realistically it will be say 1 is 1/10/1984, whereas 1990 may have a 365.25 *6 increase.

Thanks for all your input thus far

Resolved

Upvotes: 0

Views: 106

Answers (2)

User9995555
User9995555

Reputation: 1556

Try this....

    Dim date1 As New Date(1990, 10, 01)

    Dim newDate = date1.AddDays(1000)

    Dim dateInterval = newDate.Subtract(date1).TotalDays

'newDate' is now 1000 days after 1990, 10, 01

and

'dateInterval' should = 1000 days

Hope that helps....

Upvotes: 2

Scott Marcus
Scott Marcus

Reputation: 65825

Does the integer that you are using matter? If not, just use Ticks:

// Convert current date/time to ticks
Dim n As Long = Now.Ticks

// Make ticks into new Date/time
Dim d As Date = New Date(n)

Upvotes: 0

Related Questions