If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Date difference function (time elapsed)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-19-06, 16:14
svgiles svgiles is offline
Registered User
 
Join Date: Oct 2004
Posts: 10
Question Date difference function (time elapsed)

Hi, I am wondering if anyone knows where to find a function that returns the time elapsed between two dates.
I have todays date and a date in the past in the form mm/dd/yyyy and need to have the number of years, months, and days that have elapsed. For example, since mm/dd/yyyy - "5 years 2 months and 12 days have passed"
The Datediff function does not do this completely.
Any input would incredibly appreciated.
Thanks!!!
Steve

Last edited by svgiles; 08-19-06 at 16:22.
Reply With Quote
  #2 (permalink)  
Old 09-11-06, 22:48
kscheidel kscheidel is offline
Registered User
 
Join Date: Mar 2004
Posts: 5
Computed time elapsed

Well, Steve, you DID say ANY input!!

While likely not the most accurate mathematically, here's where I am so far. I think works using DayOfYear as opposed to Day but dMonth creates the inaccuracy. Might be able to get a better algorithm once I think more about it:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim EndDate, StartDate As Date
Dim dYears, dMonth, dDays As String

StartDate = Convert.ToDateTime(TextBox1.Text)
EndDate = Convert.ToDateTime(TextBox2.Text)
dYears = DateDiff(DateInterval.Year, StartDate, EndDate)
dMonth = DateDiff(DateInterval.Month, StartDate, EndDate) - (dYears * 12)
dDays = (DateDiff(DateInterval.DayOfYear, StartDate, EndDate) - (dYears * 365) - (dMonth * 30))

Label1.Text = dYears & "Year(s), " & dMonth & " Month(s), " & dDays & " Day(s) have passed."
End Sub


Best to you,
MKS

Last edited by kscheidel; 09-11-06 at 22:55.
Reply With Quote
  #3 (permalink)  
Old 09-11-06, 23:07
svgiles svgiles is offline
Registered User
 
Join Date: Oct 2004
Posts: 10
Thank you!!

Thank you, MKS!!
I do very much appreciate your input!!
-Steve
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On