One of the problems with datediff function is that even if the two dates are 31-12-2011 and 01-01-2012,it will show the difference as 1 year.How to overcome this problem????
bigzos 0 Light Poster
Recommended Answers
Jump to PostNo, Icannot be, or you did it wrong. Check this example:
Dim d1 As New DateTime(2011, 12, 31) Dim d2 As New DateTime(2012, 1, 1) Dim ts As TimeSpan = d2.Subtract(d1) Console.WriteLine("Difference between these two times is:" & vbCr & vbLf & "years: {0}" & vbCr & …
Jump to PostCan you use DateTime and TimeSpan?
They've never failed me.
Jump to PostWhen you subtract a DateTime from a DateTime, it creates a TimeSpan.
Module Module1 Sub Main() Dim dtOne As New DateTime(2011, 12, 31) '31 Dec, 2011' Dim dtTwo As New DateTime(2012, 1, 1) ' 1 Jan, 2012' Dim tsDiff As TimeSpan = (dtTwo - dtOne) '' System.Diagnostics.Debug.WriteLine(String.Format("DAYS={0}", …
Jump to PostIn that case you are misusing the term "exact". Unless you mean you want a result of 1 when the difference is exactly one year. If you are not interested in fractions of a year then do as was suggested and find the difference in days then take the integer …
Jump to Posthere you go
‘” & Int(DateDiff("d", DateTimePicker1.Text, Now(), FirstDayOfWeek.Monday, FirstWeekOfYear.FirstFourDays) / 365) & "'
All 17 Replies
poojavb 29 Junior Poster
Mitja Bonca 557 Nearly a Posting Maven
G_Waddell 131 Posting Whiz in Training
poojavb 29 Junior Poster
bigzos 0 Light Poster
poojavb 29 Junior Poster
bigzos 0 Light Poster
poojavb 29 Junior Poster
thines01 401 Postaholic Team Colleague Featured Poster
poojavb 29 Junior Poster
thines01 401 Postaholic Team Colleague Featured Poster
poojavb 29 Junior Poster
bigzos 0 Light Poster
thines01 401 Postaholic Team Colleague Featured Poster
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
guy40az 0 Junior Poster in Training
poojavb 29 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.