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 Post— poojavb 29SO how do u want to display the date difference??? in months, year or days??? whatever parameter u will give in the date diff function it will be dependent on that....
Jump to Post— Mitja Bonca 557No, 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 Post— G_Waddell 131I agree you must be entering the wrong syntax...
e.g. I want to find the difference between date1 and date2 in days,
datediff( day, date1, date2)I want to know the difference in Hours datediff( hour, date1, date2)
Jump to Post— poojavb 29if u are entering the datediff as years then it will show 1 yr as 2011 and 2012 has a diff of 1....
Jump to Post— Reverend Jim 6,665In 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 …
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 6,665 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.