Reputation: 10037
Today is 3/12/2009 and based on today's date. I want to get the start date of this year and that will be 1/1/2009. Does anyone know if there is a way to do this? The reason for this is i want to get the DateDiff of today's date against the start date of today's date's year.
Jack
Upvotes: 2
Views: 15305
Reputation: 754545
Try this
EDIT As Konrad pointed out, just keep it simple
VS Any version
Dim year As New DateTime(DateTime.Now.Year, 1, 1)
VS2008 (with Option Infer On )
Dim year = new DateTime(DateTime.Now.Year, 1, 1)
VS2005 or VS2008 (with Option Infer Off)
Dim year As DateTime = new DateTime(DateTime.Now.Year, 1, 1)
Upvotes: 14
Reputation: 11773
Dim day1 As DateTime = New DateTime(DateTime.Now.Year, 1, 1)
Dim ts As TimeSpan
'
ts = DateTime.Now - day1
'
Label1.Text = ts.Days.ToString
'or
Label1.Text = ts.TotalDays.ToString
Upvotes: 0
Reputation: 26940
There is the DayOfYear date method in answer to your last question...
Dim d As New Date(2009, 3, 12)
Console.WriteLine(d.DayOfYear) '71
Console.WriteLine(DateDiff(DateInterval.Day, New Date(d.Year, 1, 1), d)) '70
Upvotes: 1