From dePoPo.net

Working with dates and times in vb.net

Posted in: General vb.NET
By dePoPo
Mar 6, 2009 - 12:12:12 PM

Some examples of Working with dates and times in vb.net



Dim somedtvar As DateTime
Dim someint As Integer
 
' current date and time
 somedtvar = DateTime.Now
 
' day of the week
 someint = DateTime.Now.Day
 
' or
 somedtvar = DateTime.Now
 someint = somedtvar.Day
 
' get the date part only
 somestring = DateTime.Now.Date
 
' get the time part only
 somestring = DateTime.Now.Time
 
 
' Calculate the number of days between today and a stored value
Dim numofdays As TimeSpan
numofdays = DateTime.Now - somedatevariable
' numofdays now contains a timespan object
MsgBox("The number of days is: " & numofdays.Days)

© Copyright 2010 by dePoPo.net