429,302 Members | 3,621 Online
Need help? Post your question and get tips & solutions from a community of 429,302 IT Pros & Developers. It's quick & easy.

# Trying to get a Date Breakdown

 P: n/a I am trying to get a overall difference on two dates, I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds, no problems... What I cannot seem to figure out is how to get: 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds. The hardest part of that, the part I cannot figure out, is the Month section... all the others are static, defined length components, but Months change, are all different... Help! anyone know how you do this? I am stuck... Thanks So Much for your Help! Atley Nov 20 '05 #1
16 Replies

 P: n/a what about getting the difference incerementally. 1st you get the difference in Year and substract it 2nd you get the difference in month and substract it 3rd .... (etc ...) "Atley" wrote in message news:OI**************@TK2MSFTNGP12.phx.gbl... I am trying to get a overall difference on two dates, I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds, no problems... What I cannot seem to figure out is how to get: 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds. The hardest part of that, the part I cannot figure out, is the Month section... all the others are static, defined length components, but Months change, are all different... Help! anyone know how you do this? I am stuck... Thanks So Much for your Help! Atley Nov 20 '05 #2

 P: n/a Yeah, I thought of that, but how do I decide what to delete from the total, based on how many months? "Lloyd Dupont" wrote in message news:eM*************@TK2MSFTNGP12.phx.gbl... what about getting the difference incerementally. 1st you get the difference in Year and substract it 2nd you get the difference in month and substract it 3rd .... (etc ...) "Atley" wrote in message news:OI**************@TK2MSFTNGP12.phx.gbl... I am trying to get a overall difference on two dates, I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds, no problems... What I cannot seem to figure out is how to get: 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds. The hardest part of that, the part I cannot figure out, is the Month section... all the others are static, defined length components, but Months change, are all different... Help! anyone know how you do this? I am stuck... Thanks So Much for your Help! Atley Nov 20 '05 #3

 P: n/a I don't get you. wether month have different lenght or you modify start or end date, the result should be the same (I guess) like 2 Feb (2) 2002 - 1st Jan (1) 2001 = 1Y + (2 Feb 2001 - 1st Jan 2001) OR 1 year + (2 Feb 2002 - 1st Jan 2002) = 1Y + 1M + (2 Jan 2001 - 1st Jan 2001) OR 1Y+1M+(2Feb2002-1stFeb2002) = 1Y + 1M + 1D OR 1Y + 1M + 1D isn't it ? "Atley" wrote in message news:up**************@TK2MSFTNGP10.phx.gbl... Yeah, I thought of that, but how do I decide what to delete from the total, based on how many months? "Lloyd Dupont" wrote in message news:eM*************@TK2MSFTNGP12.phx.gbl... what about getting the difference incerementally. 1st you get the difference in Year and substract it 2nd you get the difference in month and substract it 3rd .... (etc ...) "Atley" wrote in message news:OI**************@TK2MSFTNGP12.phx.gbl... I am trying to get a overall difference on two dates, I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds, no problems... What I cannot seem to figure out is how to get: 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds. The hardest part of that, the part I cannot figure out, is the Month section... all the others are static, defined length components, but Months change, are all different... Help! anyone know how you do this? I am stuck... Thanks So Much for your Help! Atley Nov 20 '05 #4

 P: n/a Yea, but how would you do that in code, that will work for any dates put in? What I am saying is I can't find the constructs or methods that will do this effectively. "Lloyd Dupont" wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... I don't get you. wether month have different lenght or you modify start or end date, the result should be the same (I guess) like 2 Feb (2) 2002 - 1st Jan (1) 2001 = 1Y + (2 Feb 2001 - 1st Jan 2001) OR 1 year + (2 Feb 2002 - 1st Jan 2002) = 1Y + 1M + (2 Jan 2001 - 1st Jan 2001) OR 1Y+1M+(2Feb2002-1stFeb2002) = 1Y + 1M + 1D OR 1Y + 1M + 1D isn't it ? "Atley" wrote in message news:up**************@TK2MSFTNGP10.phx.gbl... Yeah, I thought of that, but how do I decide what to delete from the total, based on how many months? "Lloyd Dupont" wrote in message news:eM*************@TK2MSFTNGP12.phx.gbl... what about getting the difference incerementally. 1st you get the difference in Year and substract it 2nd you get the difference in month and substract it 3rd .... (etc ...) "Atley" wrote in message news:OI**************@TK2MSFTNGP12.phx.gbl... > I am trying to get a overall difference on two dates, > > I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, > Seconds, no problems... > > What I cannot seem to figure out is how to get: > > 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds. > > The hardest part of that, the part I cannot figure out, is the Month > section... all the others are static, defined length components, but Months > change, are all different... > > Help! anyone know how you do this? I am stuck... > > Thanks So Much for your Help! > > Atley > > Nov 20 '05 #5

 P: n/a I'm not sure I understand exactly what the problem is, but isn't it just something as simple as: Dim d1 As New Date(2006, 10, 20) Dim d2 As New Date(2003, 1, 9) Dim yDiff As Integer = d1.Year - d2.Year Dim mDiff As Integer = d1.Month - d2.Month Dim dDiff As Integer = d1.Day - d2.Day Or are you asking for something more complicated? Steven "Atley" wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... Yea, but how would you do that in code, that will work for any dates put in? What I am saying is I can't find the constructs or methods that will do this effectively. "Lloyd Dupont" wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... I don't get you. wether month have different lenght or you modify start or end date, the result should be the same (I guess) like 2 Feb (2) 2002 - 1st Jan (1) 2001 = 1Y + (2 Feb 2001 - 1st Jan 2001) OR 1 year + (2 Feb 2002 - 1st Jan 2002) = 1Y + 1M + (2 Jan 2001 - 1st Jan 2001) OR 1Y+1M+(2Feb2002-1stFeb2002) = 1Y + 1M + 1D OR 1Y + 1M + 1D isn't it ? "Atley" wrote in message news:up**************@TK2MSFTNGP10.phx.gbl... Yeah, I thought of that, but how do I decide what to delete from the total, based on how many months? "Lloyd Dupont" wrote in message news:eM*************@TK2MSFTNGP12.phx.gbl... > what about getting the difference incerementally. > > 1st you get the difference in Year and substract it > 2nd you get the difference in month and substract it > 3rd .... (etc ...) > > "Atley" wrote in message > news:OI**************@TK2MSFTNGP12.phx.gbl... > > I am trying to get a overall difference on two dates, > > > > I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, > > Seconds, no problems... > > > > What I cannot seem to figure out is how to get: > > > > 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds. > > > > The hardest part of that, the part I cannot figure out, is the Month > > section... all the others are static, defined length components, but > Months > > change, are all different... > > > > Help! anyone know how you do this? I am stuck... > > > > Thanks So Much for your Help! > > > > Atley > > > > > > Nov 20 '05 #6

 P: n/a Hi Atley, Did you know that Date is the topic of this week on MSDN http://msdn.microsoft.com/netframewo...tetimecode.asp Cor Nov 20 '05 #7

 P: n/a something like this? dim date1 as datetime dim date2 as datetime dim ticks1 as long = date1.ticks dim ticks2 as long = date2.ticks dim difference as new timespan(math.abs(ticks1 - ticks2)) Dominique "Atley" wrote in message news:OI**************@TK2MSFTNGP12.phx.gbl... I am trying to get a overall difference on two dates, I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds, no problems... What I cannot seem to figure out is how to get: 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds. The hardest part of that, the part I cannot figure out, is the Month section... all the others are static, defined length components, but Months change, are all different... Help! anyone know how you do this? I am stuck... Thanks So Much for your Help! Atley Nov 20 '05 #8

 P: n/a Thanks, but i can get the DateDiff several different ways, the problem is with the breakdown into how much time is left as a rundown ie 1 year, 2 months, 1 week, 3 days, 6 hours, 23 minutes, 41 seconds... "Dominique Vandensteen" wrote in message news:OK*************@TK2MSFTNGP11.phx.gbl... something like this? dim date1 as datetime dim date2 as datetime dim ticks1 as long = date1.ticks dim ticks2 as long = date2.ticks dim difference as new timespan(math.abs(ticks1 - ticks2)) Dominique "Atley" wrote in message news:OI**************@TK2MSFTNGP12.phx.gbl... I am trying to get a overall difference on two dates, I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds, no problems... What I cannot seem to figure out is how to get: 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds. The hardest part of that, the part I cannot figure out, is the Month section... all the others are static, defined length components, but Months change, are all different... Help! anyone know how you do this? I am stuck... Thanks So Much for your Help! Atley Nov 20 '05 #9

 P: n/a Hi Atley, Did you look at the timespan.tickspersecond timespan.ticksperyear timespan.ticksperhour etc. I hope this helps, Cor Nov 20 '05 #10

 P: n/a aha you can do somthing like this... dim date1 as datetime dim date2 as datetime dim ticks1 as long = date1.ticks dim ticks2 as long = date2.ticks Dim dt As New DateTime(math.abs(ticks1 - ticks2)) Dim msg As String = "Differnce is:" & vbCrLf & _ "years: " & (dt.Year - 1) & vbCrLf & _ "months: " & (dt.Month - 1) & vbCrLf & _ "days: " & (dt.Day - 1) & vbCrLf & _ "hours: " & dt.Hour & vbCrLf & _ "minutes: " & dt.Minute & vbCrLf & _ "seconds: " & dt.Second doing -1 for year, month and day: new datetime(ticks as long) -> gives you a date, not a timespan and the date is calculated as the number of ticks since 01-01-0001 00:00:00 so doing -1 for day, month and year gives you the remaining time for each datetime part isn't that kewl :-) something not so kewl try this date1 = now date2 = date1.addYear(1) result everything 0 except for year... and day (also 1) tried a little with other "year-add's" 90 -> year=90, day=1 99 -> year=99, day=0 wellwell, bug for small number of add years only? or am I missing something? "Atley" wrote in message news:eY**************@TK2MSFTNGP10.phx.gbl... Thanks, but i can get the DateDiff several different ways, the problem is with the breakdown into how much time is left as a rundown ie 1 year, 2 months, 1 week, 3 days, 6 hours, 23 minutes, 41 seconds... "Dominique Vandensteen" wrote in message news:OK*************@TK2MSFTNGP11.phx.gbl... something like this? dim date1 as datetime dim date2 as datetime dim ticks1 as long = date1.ticks dim ticks2 as long = date2.ticks dim difference as new timespan(math.abs(ticks1 - ticks2)) Dominique "Atley" wrote in message news:OI**************@TK2MSFTNGP12.phx.gbl... I am trying to get a overall difference on two dates, I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds, no problems... What I cannot seem to figure out is how to get: 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds. The hardest part of that, the part I cannot figure out, is the Month section... all the others are static, defined length components, but Months change, are all different... Help! anyone know how you do this? I am stuck... Thanks So Much for your Help! Atley Nov 20 '05 #11

 P: n/a Dominique, You know you can shorten that to: dim date1 as datetime dim date2 as datetime dim difference as timespan = date2.Subtract(date1) Which assumes that date2 is after date1. Hope this helps Jay "Dominique Vandensteen" wrote in message news:OK*************@TK2MSFTNGP11.phx.gbl... something like this? dim date1 as datetime dim date2 as datetime dim ticks1 as long = date1.ticks dim ticks2 as long = date2.ticks dim difference as new timespan(math.abs(ticks1 - ticks2)) Dominique "Atley" wrote in message news:OI**************@TK2MSFTNGP12.phx.gbl... I am trying to get a overall difference on two dates, I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds, no problems... What I cannot seem to figure out is how to get: 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds. The hardest part of that, the part I cannot figure out, is the Month section... all the others are static, defined length components, but Months change, are all different... Help! anyone know how you do this? I am stuck... Thanks So Much for your Help! Atley Nov 20 '05 #12

 P: n/a Dominique, How about Dim difference as TimeSpan = date2.Subtract(date1) difference = difference.Duration() ' correct to positive offset Now years is difference.Days/365 (ignoring leap year effects 365 days/year) Days = difference.Days Mod 365 hours, minutes and seconds are directly readable from the timespan. Ron Allen "Jay B. Harlow [MVP - Outlook]" wrote in message news:ep**************@TK2MSFTNGP09.phx.gbl... Dominique, You know you can shorten that to: dim date1 as datetime dim date2 as datetime dim difference as timespan = date2.Subtract(date1) Which assumes that date2 is after date1. Hope this helps Jay "Dominique Vandensteen" wrote in message news:OK*************@TK2MSFTNGP11.phx.gbl... something like this? dim date1 as datetime dim date2 as datetime dim ticks1 as long = date1.ticks dim ticks2 as long = date2.ticks dim difference as new timespan(math.abs(ticks1 - ticks2)) Dominique "Atley" wrote in message news:OI**************@TK2MSFTNGP12.phx.gbl... I am trying to get a overall difference on two dates, I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds, no problems... What I cannot seem to figure out is how to get: 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds. The hardest part of that, the part I cannot figure out, is the Month section... all the others are static, defined length components, but Months change, are all different... Help! anyone know how you do this? I am stuck... Thanks So Much for your Help! Atley Nov 20 '05 #13

 P: n/a Sweet... It works like a charm... you are the best! thanks for the help. "Dominique Vandensteen" wrote in message news:uS*************@TK2MSFTNGP11.phx.gbl... aha you can do somthing like this... dim date1 as datetime dim date2 as datetime dim ticks1 as long = date1.ticks dim ticks2 as long = date2.ticks Dim dt As New DateTime(math.abs(ticks1 - ticks2)) Dim msg As String = "Differnce is:" & vbCrLf & _ "years: " & (dt.Year - 1) & vbCrLf & _ "months: " & (dt.Month - 1) & vbCrLf & _ "days: " & (dt.Day - 1) & vbCrLf & _ "hours: " & dt.Hour & vbCrLf & _ "minutes: " & dt.Minute & vbCrLf & _ "seconds: " & dt.Second doing -1 for year, month and day: new datetime(ticks as long) -> gives you a date, not a timespan and the date is calculated as the number of ticks since 01-01-0001 00:00:00 so doing -1 for day, month and year gives you the remaining time for each datetime part isn't that kewl :-) something not so kewl try this date1 = now date2 = date1.addYear(1) result everything 0 except for year... and day (also 1) tried a little with other "year-add's" 90 -> year=90, day=1 99 -> year=99, day=0 wellwell, bug for small number of add years only? or am I missing something? "Atley" wrote in message news:eY**************@TK2MSFTNGP10.phx.gbl... Thanks, but i can get the DateDiff several different ways, the problem is with the breakdown into how much time is left as a rundown ie 1 year, 2 months, 1 week, 3 days, 6 hours, 23 minutes, 41 seconds... "Dominique Vandensteen" wrote in message news:OK*************@TK2MSFTNGP11.phx.gbl... something like this? dim date1 as datetime dim date2 as datetime dim ticks1 as long = date1.ticks dim ticks2 as long = date2.ticks dim difference as new timespan(math.abs(ticks1 - ticks2)) Dominique "Atley" wrote in message news:OI**************@TK2MSFTNGP12.phx.gbl... > I am trying to get a overall difference on two dates, > > I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, > Seconds, no problems... > > What I cannot seem to figure out is how to get: > > 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds. > > The hardest part of that, the part I cannot figure out, is the Month > section... all the others are static, defined length components, but Months > change, are all different... > > Help! anyone know how you do this? I am stuck... > > Thanks So Much for your Help! > > Atley > > Nov 20 '05 #14

 P: n/a Ron, Yea that works, and that is pretty much what I was doing, except you have the exact same problem with months that I did. "Ron Allen" wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... Dominique, How about Dim difference as TimeSpan = date2.Subtract(date1) difference = difference.Duration() ' correct to positive offset Now years is difference.Days/365 (ignoring leap year effects 365 days/year) Days = difference.Days Mod 365 hours, minutes and seconds are directly readable from the timespan. Ron Allen "Jay B. Harlow [MVP - Outlook]" wrote in message news:ep**************@TK2MSFTNGP09.phx.gbl... Dominique, You know you can shorten that to: dim date1 as datetime dim date2 as datetime dim difference as timespan = date2.Subtract(date1) Which assumes that date2 is after date1. Hope this helps Jay "Dominique Vandensteen" wrote in message news:OK*************@TK2MSFTNGP11.phx.gbl... something like this? dim date1 as datetime dim date2 as datetime dim ticks1 as long = date1.ticks dim ticks2 as long = date2.ticks dim difference as new timespan(math.abs(ticks1 - ticks2)) Dominique "Atley" wrote in message news:OI**************@TK2MSFTNGP12.phx.gbl... > I am trying to get a overall difference on two dates, > > I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, > Seconds, no problems... > > What I cannot seem to figure out is how to get: > > 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds. > > The hardest part of that, the part I cannot figure out, is the Month > section... all the others are static, defined length components, but Months > change, are all different... > > Help! anyone know how you do this? I am stuck... > > Thanks So Much for your Help! > > Atley > > Nov 20 '05 #15

 P: n/a What is a year? What is a month? Peter Seaman Nov 20 '05 #16

 P: n/a well I used the dateTime and not the TimeSpan just to have an easy way to find the years, months and days... "Ron Allen" wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... Dominique, How about Dim difference as TimeSpan = date2.Subtract(date1) difference = difference.Duration() ' correct to positive offset Now years is difference.Days/365 (ignoring leap year effects 365 days/year) Days = difference.Days Mod 365 hours, minutes and seconds are directly readable from the timespan. Ron Allen "Jay B. Harlow [MVP - Outlook]" wrote in message news:ep**************@TK2MSFTNGP09.phx.gbl... Dominique, You know you can shorten that to: dim date1 as datetime dim date2 as datetime dim difference as timespan = date2.Subtract(date1) Which assumes that date2 is after date1. Hope this helps Jay "Dominique Vandensteen" wrote in message news:OK*************@TK2MSFTNGP11.phx.gbl... something like this? dim date1 as datetime dim date2 as datetime dim ticks1 as long = date1.ticks dim ticks2 as long = date2.ticks dim difference as new timespan(math.abs(ticks1 - ticks2)) Dominique "Atley" wrote in message news:OI**************@TK2MSFTNGP12.phx.gbl... > I am trying to get a overall difference on two dates, > > I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, > Seconds, no problems... > > What I cannot seem to figure out is how to get: > > 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds. > > The hardest part of that, the part I cannot figure out, is the Month > section... all the others are static, defined length components, but Months > change, are all different... > > Help! anyone know how you do this? I am stuck... > > Thanks So Much for your Help! > > Atley > > Nov 20 '05 #17

### This discussion thread is closed

Replies have been disabled for this discussion.