Changes

Working with Dates and Times in Visual Basic

1,054 bytes added, 20:06, 2 August 2007
Finding the Interval Between Two Dates or Times
DateDiff(DateInterval.Month, #08/02/2006#, #08/02/2007# ) ' one year difference so returns 12 (months)
</pre>
 
== Accessing the System Date and Time from Visual Basic ==
 
One ofthe most common tasks related to dates and times in a Visual Basic application involves getting the current system date and time. This is achieved using the Visual basic DateTime object. The DateTime object contains a number of properties, the most important of which are ''Now'' and ''Today''. The ''Today'' property returns the current date held by the system. For example:
 
<pre>
Dim objCurrentDate As Date = DateTime.Today
</pre>
 
The ''Now'' property of the Visual Basic DateTime object contains both the date and the current system time. For example:
 
<pre>
Dim objCurrentDate As Date = DateTime.Now
</pre>
 
== Checking if a Value is a Date ==
 
Visual Basic provides the ''IsDate()'' function to ascertain whether a value is a valid date or not. This can be useful for checking that a user has entered a valid date into TextBox control. The ''IsDate()'' function takes a value as a parameter and returns ''True'' or ''False'' depending on whether the value is a valid date or not.