Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
sTime = "7/29/2007 4:15:00 AM"
eTime = "8/1/2007 6:29:50 PM"
WScript.Echo datediffToWords(sTime, eTime)
Function datediffToWords(d1, d2)
months = Int(DateDiff("m",d1,d2))
WScript.Echo months & " months"
End Function
sTime = "6/30/2002 4:15:00 PM"
eTime = "9/30/2007 5:25:50 PM"
WScript.Echo datediffToWords(sTime, eTime)
Function datediffToWords(d1, d2)
report = ""
days = DateDiff("d",d1,d2)
If days > 365 Then
years = days\365
days = days Mod (365*years)-1
Else
years = 0
End If
report = years & " Year(s), " & days & " Day(s)"
datediffToWords = report
End Function
sTime = "7/29/2007 4:15:00 AM"
eTime = "8/1/2007 6:29:50 PM"
WScript.Echo datediffToWords(sTime, eTime)
Function datediffToWords(d1, d2)
fullmonthStart = Month(d1) + 1 & "/1/" & Year(d1)
months = Int(DateDiff("m",fullmonthStart,d2))
WScript.Echo months & " months"
End Function
months = Int(DateDiff("m",d1,d2))+(day(d2)<day(d1))
[green]
'==========================================================================
'
' NAME: DateDiffToWords.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: http://www.thespidersparlor.com
' DATE : 6/9/2007
' COPYRIGHT (c) 2007 All Rights Reserved
'
' COMMENT: Reports Years, months, days, hours, minutes, seconds between dates
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'
' IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS
' BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
' DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
' WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
' ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
' OF THIS CODE OR INFORMATION.
'
'==========================================================================
[/green]
sTime = "6/30/2002 4:15:00 PM"
eTime = "9/30/2007 5:25:50 PM"
WScript.Echo datediffToWords(sTime, eTime)
Function datediffToWords(d1, d2)
report = ""
[green]'Start with total number of days[/green]
days = DateDiff("d",d1,d2)
[green]'Convert days to years and grab remaining days[/green]
If days > 365 Then
years = days\365
days = days Mod (365*years)-1
report = years & " Year(s), "
Else
years = 0
End If
[green]'Thank you PHV for help simplifying the month calculation
'Compute the number of months[/green]
months = Int(DateDiff("m",d1,d2))+(day(d2)<day(d1))
[green]'remove years from the total months[/green]
months = months Mod 12
report = report & Months & " Month(s), "
[green]'now find the days[/green]
newStart = Month(d1) & "/" & Day(d1) & "/" & Year(d1) + years
If Month(d1) <> 12 Then
fullmonthStart = Month(d1) + 1 & "/1/" & Year(d1) + years
Else
fullmonthStart = "1/1/" & Year(d1) + years +1
End If
If Day(d1) =< Day(d2) Then
days = Day(d2) - Day(d1)
Else
days = DateDiff("d", newStart, fullmonthStart) + Day(d2) -1
End If
If days > 0 Then
report = report & days & " day(s), "
End If
[green]
'now we will deal with the time left over
'begin by getting total seconds between dates and divide out the days
'grab the remaining seconds with the mod operator[/green]
Seconds = abs(datediff("S", d1, d2))
if Seconds <= 0 then
report = "0 seconds."
else
Seconds = Seconds mod (24*60*60)
[green]'divide by 3600 to get hours[/green]
If Seconds >= 3600 then
report = report & _
Seconds\(3600) & " hours(s), "
end If
[green]'use mod to get remaining seconds and divide to get minutes[/green]
Seconds = Seconds mod (60*60)
if Seconds >= 60 then
report = report & _
Seconds\(60) & " minutes(s), "
end If
[green]'use mod to get remaining seconds[/green]
seconds = Seconds Mod (60)
report = report & seconds & " second(s)"
end if
datediffToWords = report
End Function