Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calculating Time Difference using DateDiff Function in VBScript

1,241 views
Skip to first unread message

nilesh

unread,
Jul 15, 1999, 3:00:00 AM7/15/99
to
Hello Friends,

I am trying to find difference between two time values. I am using the code
given below.

<!-- #Include file="ADOVBS.INC" -->
<%
xx = "23:55"
yy = "22:00"
xxx = FormatDateTime(xx, vbShortTime)
yyy = FormatDateTime(yy, vbShortTime)
response.write (xxx)
response.write (yyy)
zz=DateDiff(h, xxx, yyy)
response.write (zz)
%>

But I get the error as below:

23:5522:00
Microsoft VBScript runtime error '800a0005'

Invalid procedure call or argument: 'DateDiff'

Can anybody help??


François Desfossés

unread,
Jul 16, 1999, 3:00:00 AM7/16/99
to
maybe those little code will help ...


Function DateDiffInMinutes(Date1, Date2)

Dim m_yerDate1
Dim m_yerDate2
Dim m_monDate1
Dim m_monDate2
Dim m_dayDate1
Dim m_dayDate2
Dim m_hrDate1
Dim m_hrDate2
Dim m_minDate1
Dim m_minDate2
Dim m_secDate1
Dim m_secDate2
Dim m_minElapsed1
Dim m_monthdays
Dim m_minElapsed2

m_yerDate1 = CInt(Year(Date1)) - 1992 - 1
m_yerDate2 = CInt(Year(Date2)) - 1992 - 1
m_monDate1 = CInt(Month(Date1)) - 1
m_monDate2 = CInt(Month(Date2)) - 1
m_dayDate1 = CInt(Day(Date1)) - 1
m_dayDate2 = CInt(Day(Date2)) - 1
m_hrDate1 = CInt(Hour(Date1))
m_hrDate2 = CInt(Hour(Date2))
m_minDate1 = CInt(Minute(Date1))
m_minDate2 = CInt(Minute(Date2))
m_secDate1 = CInt(Second(Date1))
m_secDate2 = CInt(Second(Date2))
m_minElapsed1 = YearInDays(m_yerDate1) * 1440
m_monthdays = MonthInDays(m_monDate1, IsLeapYear(m_yerDate1 + 1))
m_minElapsed1 = m_minElapsed1 + m_monthdays * 1440
m_minElapsed1 = m_minElapsed1 + m_dayDate1 * 1440
m_minElapsed1 = m_minElapsed1 + m_hrDate1 * 60 + m_minDate1
m_minElapsed2 = YearInDays(m_yerDate2) * 1440
m_monthdays = MonthInDays(m_monDate2, IsLeapYear(m_yerDate2 + 1))
m_minElapsed2 = m_minElapsed2 + m_monthdays * 1440
m_minElapsed2 = m_minElapsed2 + m_dayDate2 * 1440
m_minElapsed2 = m_minElapsed2 + m_hrDate2 * 60 + m_minDate2

g_DateDiff = m_minElapsed2 - m_minElapsed1

' Return 1 for success
DateDiffInMinutes = 1
End Function
----------------------------------------------------------------------------
---------------------------------


--
François Desfossés
Programmeur stagiaires, systèmes bureautiques
Trainee programmer, office systems
Technologie de l'information/Information Technologies
Agence spatiale canadienne/Canadian Space Agency
francois....@space.gc.ca
Http://www.space.gc.ca


Kevin O'Brien

unread,
Jul 20, 1999, 3:00:00 AM7/20/99
to
Try.......

<%
xx = TimeValue("23:50")
yy = TimeValue("22:00")
response.write (xx & "<BR>")
response.write (yy & "<BR>")
zz=(Hour(xx)-Hour(yy))*60 + (Minute(xx)-Minute(yy))
zz=TimeSerial(0,zz,0)
response.write zz
%>

Depending on your app, you may have to adjust for +/- time values.

nilesh <nilesh.s...@timesgroup.com> wrote in message
news:#XVr3Opz#GA.310@cppssbbsa04...

Robert Zaufall

unread,
Jul 26, 1999, 3:00:00 AM7/26/99
to
Hi,

you have to put " ' "s around the parameter for the intervall.
Something like datediff('h', date1, date2)

Bye.
Robert

On Thu, 15 Jul 1999 12:59:23 +0530, "nilesh" <nilesh.s...@timesgroup.com> wrote:

>Hello Friends,
>
>...
>zz=DateDiff(h, xxx, yyy)
>...

0 new messages