+ Reply to Thread
Results 1 to 4 of 4

Time format will not exclude seconds!!

  1. #1
    sbowman
    Guest

    Time format will not exclude seconds!!

    I'm trying to capture a start time and end time entered into a userform
    and my program refuses to exclude the seconds!!! here's my code:

    Dim chkStartTime As String
    Dim chkEndTime As String
    Dim StartTime As Date
    Dim EndTime As Date

    chkStartTime = FrmDataInput.txtStartTime.Value
    chkEndTime = FrmDataInput.txtEndTime.Value

    If IsDate(chkStartTime) = False Then
    MsgBox "Please enter a valid start time in HH:MM AM/PM format.",
    vbOKOnly
    FrmDataInput.txtStartTime.SetFocus
    Exit Sub
    Else
    StartTime = Format(chkStartTime, "hh:mm AM/PM")
    End If

    If IsDate(chkEndTime) = False Then
    MsgBox "Please enter a valid end time in HH:MM AM/PM format.",
    vbOKOnly
    FrmDataInput.txtEndTime.SetFocus
    Exit Sub
    Else
    EndTime = Format(chkEndTime, "HH:MM AM/PM")
    End If


    When I step through the code and add a watch to the StartTime and End
    time I get hh:mm:ss AM/PM!!!


  2. #2
    Bernie Deitrick
    Guest

    Re: Time format will not exclude seconds!!

    Shelley,

    Either format StartTime and EndTime as Strings, or whenever you use them as date/times, use
    Format(StartTime, "HH:MM AM/PM")

    HTH,
    Bernie
    MS Excel MVP


    "sbowman" <[email protected]> wrote in message
    news:[email protected]...
    > I'm trying to capture a start time and end time entered into a userform
    > and my program refuses to exclude the seconds!!! here's my code:
    >
    > Dim chkStartTime As String
    > Dim chkEndTime As String
    > Dim StartTime As Date
    > Dim EndTime As Date
    >
    > chkStartTime = FrmDataInput.txtStartTime.Value
    > chkEndTime = FrmDataInput.txtEndTime.Value
    >
    > If IsDate(chkStartTime) = False Then
    > MsgBox "Please enter a valid start time in HH:MM AM/PM format.",
    > vbOKOnly
    > FrmDataInput.txtStartTime.SetFocus
    > Exit Sub
    > Else
    > StartTime = Format(chkStartTime, "hh:mm AM/PM")
    > End If
    >
    > If IsDate(chkEndTime) = False Then
    > MsgBox "Please enter a valid end time in HH:MM AM/PM format.",
    > vbOKOnly
    > FrmDataInput.txtEndTime.SetFocus
    > Exit Sub
    > Else
    > EndTime = Format(chkEndTime, "HH:MM AM/PM")
    > End If
    >
    >
    > When I step through the code and add a watch to the StartTime and End
    > time I get hh:mm:ss AM/PM!!!
    >




  3. #3
    sbowman
    Guest

    Re: Time format will not exclude seconds!!

    Thank You!! It works if I use Format(StartTime, "HH:MM AM/PM") whenever
    I use the variable. It sucks to have to do that, but it works and
    that's what matters.

    Shelley


  4. #4
    Ardus Petus
    Guest

    Re: Time format will not exclude seconds!!

    StartTime=round(StartTime*1440)/1440

    This will round StartTime to the nearest minute

    HTH
    --
    AP

    "sbowman" <[email protected]> a écrit dans le message de news:
    [email protected]...
    > I'm trying to capture a start time and end time entered into a userform
    > and my program refuses to exclude the seconds!!! here's my code:
    >
    > Dim chkStartTime As String
    > Dim chkEndTime As String
    > Dim StartTime As Date
    > Dim EndTime As Date
    >
    > chkStartTime = FrmDataInput.txtStartTime.Value
    > chkEndTime = FrmDataInput.txtEndTime.Value
    >
    > If IsDate(chkStartTime) = False Then
    > MsgBox "Please enter a valid start time in HH:MM AM/PM format.",
    > vbOKOnly
    > FrmDataInput.txtStartTime.SetFocus
    > Exit Sub
    > Else
    > StartTime = Format(chkStartTime, "hh:mm AM/PM")
    > End If
    >
    > If IsDate(chkEndTime) = False Then
    > MsgBox "Please enter a valid end time in HH:MM AM/PM format.",
    > vbOKOnly
    > FrmDataInput.txtEndTime.SetFocus
    > Exit Sub
    > Else
    > EndTime = Format(chkEndTime, "HH:MM AM/PM")
    > End If
    >
    >
    > When I step through the code and add a watch to the StartTime and End
    > time I get hh:mm:ss AM/PM!!!
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1