Team Fly |
Page 39
Debug.WriteLine(''Number of hours elapsed is: " + Difference.Hours.ToString) Debug.WriteLine("Number of minutes elapsed is: " + _ Difference.Minutes.ToString)
The following sections provide some additional examples that illustrate how to manipulate date and time.
Here's an example of using the AddDays method:
Dim ti As Date = TimeOfDay 'the current time Dim da As Date = Today 'the current date Dim dati As Date = Now 'the current date and time da = da.AddDays(12) ' add 12 days Debug.WriteLine("12 days from now is: " & da)
Similarly, you can use AddMinutes, AddHours, AddSeconds, AddMilliseconds, AddMonths, AddYears, and so on.
There is an OA conversion method for currency data types and for date data types. (OA stands for Ole Automation, a legacy technology that still keeps popping up.) Here is an example showing how to translate to and from the old double-precision date format:
Dim dati As Date = Now 'the current date and time Dim da as Date, n As Double n = dati.ToOADate ' translate into double-precision format n = n + 21 ' add three weeks (the integer part is the days) da = Date.FromOADate(n) ' translate the OA style into .NET style Debug.WriteLine(da)
Use Now, not Today, for these OA-style data types.
2004 is a leap year. Here's one way to prove it:
Debug.WriteLine("In the year 2004, February has " & _ Date.DaysInMonth(2004, 2).ToString & " days.") Debug.WriteLine("In the year 2005, February has " & _ Date.DaysInMonth(2005, 2).ToString & " days.")
The classic familiar VB file opening syntax is this:
Open filepath {For Mode}{options}As {#} filenumber {Len = recordlength}
Team Fly |