Alpha Video Training
Results 1 to 7 of 7

Thread: Military to Standard Time

  1. #1
    "Certified" Alphaholic
    Real Name
    Thomas Patten
    Join Date
    Apr 2000
    Location
    Duluth, MN
    Posts
    1,488

    Default Military to Standard Time

    I've spent wayyyyyyyyyyyyyyyy too much time on this.

    I need to convert military time to standard time as follows:

    1730 -> 5:30a

    My convoluted code that works in the expression builder, but not in the update operation is the following.

    IF(toseconds("1730")*3600>=43200,Left(Padl(Totime(toseconds(left("1730",2))*3600+(val(right("1730",2))*60),11,0),8,"0"),5)+"p",Left(Padl(Totime(toseconds(left("1730",2))*3600+(val(right("1730",2))*60),11,0),8,"0"),5)+"a")

    What am I doing wrong? Remember this is in A5V4.5

    Thanks

    Tom

  2. #2
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,308

    Default Re: Military to Standard Time

    Tom, does your military time always include 4 digits and no colon? i.e. 0230 for 2:30 am?

    I don't remember that A5v4 supports a "time" data type. So when you say "standard time", you're really talking only about a character data type field, right?
    Last edited by Tom Cone Jr; 12-13-2008 at 11:29 AM.

  3. #3
    "Certified" Alphaholic
    Real Name
    Thomas Patten
    Join Date
    Apr 2000
    Location
    Duluth, MN
    Posts
    1,488

    Default Re: Military to Standard Time

    Good Morning Tom

    Quote Originally Posted by Tom Cone Jr View Post
    Tom, does your military time always include 4 digits and no colon? i.e. 0230 for 2:30 am?

    I don't remember that A5v4 supports a "time" data type. So when you say "standard time", you're really talking only about a character data type field, right?
    Correct no colon and should be 4 characters, but I don't force it.


    Yes, the field is 6 characters wide. Hence the "a" or "p" to squeeze "12:30 pm" into 12:30p

    Thanks for taking a look.

    Tom

  4. #4
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,308

    Default Re: Military to Standard Time

    If you force military time to always have 4 digits you can do this, but I'm not sure it's any easier to maintain.

    Code:
    m_time = "1630"
    dim s_time as c
    s_time = if(val(left(m_time,2))< 12, left(m_time,2) + ":" + right(m_time,2) + "a", if(val(left(m_time,2)) = 12,  left(m_time,2) + ":" + right(m_time,2) + "p", ltrim(str(val(left(m_time,2)) - 12)) + ":" + right(m_time,2) + "p"))
    ?s_time
    = "4:30p"
    Last edited by Tom Cone Jr; 12-13-2008 at 12:04 PM.

  5. #5
    "Certified" Alphaholic
    Real Name
    Thomas Patten
    Join Date
    Apr 2000
    Location
    Duluth, MN
    Posts
    1,488

    Default Re: Military to Standard Time

    Tom,

    It doesn't work in the update operation. It leaves the minutes blank, but does add the "p" or "a"

    Code:
    dim s_time as c
    dim m_time as C
    m_time="1730"
    s_time = if(val(left(m_time,2))< 12, left(m_time,2) + ":" + right(m_time,2) + "a", if(val(left(m_time,2)) = 12, left(m_time,2) + ":" + right(m_time,2) + "p", ltrim(str(val(left(m_time,2)) - 12)) + ":" + right(m_time,2) + "p"))
    ?s_time
    = ""

    The above code in the expression builder works fine, but in the interactive window it results in ""

    ????

    Tom

  6. #6
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,308

    Default Re: Military to Standard Time

    If your field width for military time is more than 4, it's likely the

    right(m_time,2)

    is simply supplying blanks, since the trailing blanks are the last two chars stored in the field

    Trim your field width.

    My example assumes a width of 4, with all places filled.

  7. #7
    "Certified" Alphaholic
    Real Name
    Thomas Patten
    Join Date
    Apr 2000
    Location
    Duluth, MN
    Posts
    1,488

    Default Re: Military to Standard Time

    YEsssssssssssssssssssss!!

    There is a Santa Clause and I got my present early!

    Tom - Thank you very much.

Similar Threads

  1. platinum with standard
    By John Lemisch in forum Alpha Five Version 9 - Desktop Applications
    Replies: 5
    Last Post: 07-28-2008, 03:18 PM
  2. Standard to Platinum
    By Steve Workings in forum Alpha Five Version 9 - Desktop Applications
    Replies: 1
    Last Post: 06-23-2008, 10:00 PM
  3. military time
    By Edward F. Schulz in forum Alpha Five Version 4
    Replies: 10
    Last Post: 06-19-2002, 02:04 PM
  4. Problem: Decimal time to Standard Time
    By GregOnline in forum Alpha Five Version 4
    Replies: 3
    Last Post: 09-11-2001, 04:22 PM
  5. Problem:Decimal Time to Standard Time
    By GregOnline in forum Code Archive
    Replies: 5
    Last Post: 09-10-2001, 03:22 PM

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
  •