|
-
Dec 1st, 2006, 03:12 AM
#1
Thread Starter
Member
[RESOLVED] DateDiff( ) issue - difference in hours....
Hi....
I am having one serious issue in visual basic 6 DateDiff( ) function in calculating the diffference in hours
My issue is concerning CASE: 2 mainly.
For the attachment: you will need to have WinRAR to extracts the 3 vb files.
--------------------------------------------------------------------------------------------------------------------------------------------------- VB6 code in Form_Load event
----------------------------------------------------------------------------------------------------------------------------------------------------
Option Explicit
Private Sub Form_Load()
Dim strPast As Date
Dim strCurrent1 As Date, strCurrent2 As Date
Dim intTotalHours1 As Integer, intTotalHours2 As Integer
' ' ' 'Indian short date format : d/M/yyyy has to be used since i am in
' ' ' ' INDIA
' ' ' 'DateDiff() syntax : DateDiff("interval", olderdate, ' '
' ' ' ' newerdate)...PLEASE CHECK!!
strPast = "30/11/2006 10:30:00 PM"
strCurrent1 = "30/11/2006 11:45:00 PM"
strCurrent2 = "1/12/2006 12:45:00 AM"
' ' ' ' ' CASE 1:
intTotalHours1 = DateDiff("h", strPast, strCurrent1)
txtText1.Text = intTotalHours1
' ' ' ' ' output is PERFECT
' ' ' ' ' CASE 2:
intTotalHours2 = DateDiff("h", strPast, strCurrent2)
txtText2.Text = intTotalHours2
' ' ' ' How can this txtbox show : 7751 hours when actually only two
' ' ' ' hours has elapsed
End Sub
----------------------------------------------------------------------------------------------------------------------------------------------------
--
Regards,
Gautam Naidu,
E-mail me: [email protected]
-
Dec 1st, 2006, 03:20 AM
#2
Re: DateDiff( ) issue - difference in hours....
i just copied your code posted above to my new project form1_load, but it give only 2 hrs...
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Dec 1st, 2006, 03:29 AM
#3
Re: DateDiff( ) issue - difference in hours....
Instead of declarings dates as Strings and relying on coercion, try using DateSerial and TimeSerial:
VB Code:
dtmPast = DateSerial(2006, 11, 30) + TimeSerial(22,30,0)
dtmCurrent1 = DateSerial(2006, 11, 30) + TimeSerial(23,45,0)
dtmCurrent2 = DateSerial(2006, 12, 1) + TimeSerial(0,45,0)
This is much more correct as things can't go wrong and messed up with computer's locale settings.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|