Flash 6

We’ll briefly state and define what a datetime and a timespan are in C# and VB, comparing the two.

First of all, here is an example of how to use both the DateTime and the TimeSpan:

C#

public static DateTime operator -(
	DateTime d,
	TimeSpan t
)

VB

Public Shared Operator - (
	d As Date,
	t As TimeSpan
) As Date

where the params are such that the DateTime represents an instant in time, typically expressed as a date and time of day, while the TimeSpan represents a time interval.

So d is the value of date and hour on which operations may be done (like, adding or substracting the value), while t is the interval of time that has to be substracted or added.

To convert a Dateime into a TimeSan is possible. To convert a DateTime to a TimeSpan you should choose a base date or time – like maybe today’s date – and subtract it from the DateTime value you already have. The process can be reversed by adding the abovementioned date to convert back to DateTime).

Instead, if you simply want to convert a DateTime to a number, you can use the ticks property.

More specific infos about the DateTime can be found here, while more accurate definitions of what a TimeSpan is can be found here.

Other interesting links:
How to add to a DateTime the value of a TimeSpan
How to Substract the value of a TimeSpan from a DateTime

Lascia un commento