Results 1 to 12 of 12

Thread: adding in military time

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Resolved adding in military time

    im tring to get the answer +2 by takeing elasped witch is -22 from offset ?
    but its adding it
    thanks and happy 4th

    Code:
    Private Sub Command3_Click()
    Dim start1 As String
    Dim stop1 As String
    Dim elasped As String
    Dim offset As String
    
    
    
    offset = "24."
    start1 = "23."
    stop1 = "01.00"
    elasped = stop1 - start1
    
    If elasped < 1 Then
     elasped = offset - elasped
    MsgBox elasped
    
    Else
    
    MsgBox elasped
    End If
    
    
    
    
    
    
    End Sub
    Last edited by flyhigh; Jun 29th, 2012 at 07:13 AM.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: [RESOLVED] adding in military time

    i forgot about this ..im sorry
    Abs(elasped)

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: [RESOLVED] adding in military time

    You should not be using strings for math, very bad practice.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: [RESOLVED] adding in military time

    is this right with military time

    Code:
    Private Sub Command3_Click()
        Dim start1 As Double
        Dim stop1 As Double
        Dim elasped As Double
        Dim offset As Double
            offset = Val("24.")
            start1 = Val("23.")
            stop1 = Val("1.")
            elasped = stop1 - start1
            MsgBox elasped
        If elasped < 0 Then
            elasped = offset - Abs(elasped)
            MsgBox elasped
        Else
            MsgBox elasped
        End If
    
    End Sub

  5. #5
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: adding in military time

    Why use strings at all? why not:-
    code Code:
    1. Dim start1 As Double
    2. Dim stop1 As Double
    3. Dim elasped As Double
    4. Dim offset As Double
    5. offset = 24
    6. start1 = 23
    7. stop1 = 1

    And you don't need that ABS because you're only subtracting it from offset if it's negative. Why not just do this:-
    code Code:
    1. elasped = offset + elasped
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: adding in military time

    that works but the time should be 2300 or 0100

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: adding in military time

    You should be using two date objects, and then using DateDiff to get the difference in hours.... the fact that it's "Military time" is irrelevant as that's just display...


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: adding in military time

    im tring to get the difference in hours , but the time may start at anytime 11:00 pm wait form 24 or more hours and restart.

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: adding in military time

    all the more reason to use a date variable.... the difference between 6/27/2012 11:00pm and 6/28/2012 1:00am is 2 hours... but the 6/27/2012 11:00pm and 6/29/2012 1:00am is 26 hours...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: adding in military time

    No doubt you should be using a date variable and the datediff() function. If you need it displayed a certian way then you just use a format() function to get the desired result.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: adding in military time

    hey yall why does this show an hour even when its only been 40 minutes?
    does it round off the numbers?

    Code:
    If timelimit = "" Then timelimit = Format(Now())
        timenow = Format(Now())
        Label1.Caption = timelimit
        Label2.Caption = Format(Now())
        Label3.Caption = DateDiff("h", timelimit, timenow)
        datdiff = DateDiff("h", timelimit, timenow)

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: adding in military time

    hey yall timelimit is 12 and 1/2 hours ago why does this code round off to nearest number?



    Code:
    timenow = Format(Now())
    datdiff = DateDiff("h", timelimit, timenow)

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