Results 1 to 3 of 3

Thread: [RESOLVED] DateDiff( ) issue - difference in hours....

  1. #1

    Thread Starter
    Member intellogo's Avatar
    Join Date
    Nov 2006
    Location
    India
    Posts
    61

    Resolved [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]

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    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.


  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: DateDiff( ) issue - difference in hours....

    Instead of declarings dates as Strings and relying on coercion, try using DateSerial and TimeSerial:

    VB Code:
    1. dtmPast = DateSerial(2006, 11, 30) + TimeSerial(22,30,0)
    2. dtmCurrent1 = DateSerial(2006, 11, 30) + TimeSerial(23,45,0)
    3. 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
  •  



Click Here to Expand Forum to Full Width