BBS: Inland Empire Archive
Date: 02-13-93 (17:35) Number: 393
From: JIM LITTLE Refer#: NONE
To: STEVE SPENCER Recvd: NO
Subj: Military time to Normal Conf: (2) Quik_Bas
SS>I know this is going to sound terribly simple but I'm new at QB.
SS>I have begun to write some simple door programs for the Bulletin Board I am
SS>going to be setting up. I havn't been able to find out a way of taking the
SS>system time (in millitary form) and converting it to
SS>normal time (1-12) with
SS>a PM or AM on the end. Can anyone help me with this.
SS>It doesn't nead to be
SS>set up for a door program, just a function that would do this and write the
SS>output to a veriable.
After quickly whipping up some code without really thinking
about it (something I do way too often.. :) ), I decided to test it to
see if it actually worked. (And am I glad I did!) It turns out there
were lots of special cases I completely ignored in my first version. But
anyway, here's a function that converts from military time standard
time, and hopefully without any bugs:
----- Cut Here --------
DECLARE FUNCTION StandardTime$ (MilitaryTime AS INTEGER)
CONST False = 0
CONST True = NOT False
INPUT "Enter Military Time: ", time%
IF time% = -1 THEN END
PRINT "Standard Time: "; StandardTime(time%)
FUNCTION StandardTime$ (MilitaryTime AS INTEGER)
DIM am AS INTEGER
DIM hours AS INTEGER
DIM minutes AS INTEGER
DIM temptime AS STRING
hours = MilitaryTime \ 100
minutes = MilitaryTime MOD 100
IF hours < 12 OR hours = 24 THEN
am = True
IF hours = 24 OR hours = 0 THEN
hours = 12
am = False
IF hours <> 12 THEN
hours = hours - 12
temptime = LTRIM$(STR$(hours)) + ":"
IF minutes > 9 THEN
temptime = temptime + LTRIM$(STR$(minutes))
temptime = temptime + "0" + LTRIM$(STR$(minutes))
IF am THEN
temptime = temptime + " am"
temptime = temptime + " pm"
StandardTime = temptime
----- End Snip --------
Hope this helps... If you have any problems, feel free to ask.
* SLMR 2.1a * Nothing is so smiple that it can't get screwed up.
--- WM v2.06/91-0012
* Origin: Com-Dat BBS Hillsboro, OR. HST (503) 681-0543 (1:105/314)