Source language: Translate to:

Convert 24 hour time to standard time

General questions about NeoBook

Moderator: Neosoft Support

Convert 24 hour time to standard time

Postby Wrangler » Tue Jun 07, 2016 11:56 am

Anyone know of some quick code to convert 24 hour time to standard time?
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1505
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Re: Convert 24 hour time to standard time

Postby Gaev » Tue Jun 07, 2016 12:37 pm

Wrangler:

1) Can you define your requirement in detail with examples ?

2) Does this website ... http://www.timeanddate.com/worldclock/converter.html ... help any ?
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Convert 24 hour time to standard time

Postby Wrangler » Tue Jun 07, 2016 12:43 pm

I have a time in 24 hour format in a variable. I want to populate another variable with it in standard time format with am/pm. Time stored in an access field.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1505
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Re: Convert 24 hour time to standard time

Postby Gaev » Tue Jun 07, 2016 1:39 pm

wrangler:

I want to populate another variable with it in standard time format with am/pm

I thought you were talking about Standard Time ... as in Eastern Standard Time, Pacific Standard Time etc.

Time stored in an access field

Access does not support a stand alone Time field (or Date field) ... just a DateTime field.

And the format is dependent on the Regional Settings in Windows ... more info here ... https://support.office.com/en-us/articl ... 24d881b698

Before I go ahead and provide the right instructions for the wrong answer, please provide some examples ... both input and output... for both M and PM samples.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Convert 24 hour time to standard time

Postby Wrangler » Tue Jun 07, 2016 3:30 pm

Went and had a look, and I'm saving the 24 hour time in a STRING field in Access. Ex: 06:45:00 or 13:25:00. I don't use the seconds. I want to convert 06:45:00 to 6:45am or 13:25:00 to 1:25pm.

Thanks Gaev.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1505
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Re: Convert 24 hour time to standard time

Postby Gaev » Tue Jun 07, 2016 4:38 pm

Wrangler:

I used the definition of AM/PM from here ... https://www.mathsisfun.com/time.html

If you want leading zeroes ... i.e. 06:12:18 AM instead of 6:12:18 AM ... remove the optional code section at the end.

Code: Select all
StrParse "[TimeIn]" "!:" "[TimeInArray]" "[junk]"
... For the first hour of the day (0:00 to 0:59), add 12 Hours, make it "AM"
If "[TimeInArray1]" "=" "00"
   SetVar "[TimeOut]" "12:[TimeInArray2]:[TimeInArray3] AM"
EndIf
... From 1:00 to 11:59, just make it "AM"
IfEx "[TimeInArray1] > 00 AND [TimeInArray1] < 12"
   SetVar "[TimeOut]" "[TimeInArray1]:[TimeInArray2]:[TimeInArray3] AM"
EndIf
... From 12:00 to 12:59, just make it "PM"
If "[TimeInArray1]" "=" "12"
   SetVar "[TimeOut]" "[TimeInArray1]:[TimeInArray2]:[TimeInArray3] PM"
EndIf
... From 13:00 to 23:59, subtract 12 Hours, make it "PM"
IfEx "[TimeInArray1] > 12 AND [TimeInArray1] < 24"
   Math "[TimeInArray1]-12" "0" "[TimeOutHH]"
   SetVar "[TimeOut]" "[TimeOutHH]:[TimeInArray2]:[TimeInArray3] PM"
EndIf
... optional: remove leading zero from hour
SubStr "[TimeOut]" "1" "1" "[FirstHour]"
If "[FirstHour]" "=" "!0"
   SubStr "[TimeOut]" "2" "999" "[TimeOut]"
EndIf
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Convert 24 hour time to standard time

Postby Wrangler » Tue Jun 07, 2016 4:50 pm

Works like a charm, buddy. As usual, thank you for the help. You've always had a good head for this kind of stuff. Me, it goes right over top. :)
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1505
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA


Return to General NeoBook Discussions

Who is online

Users browsing this forum: No registered users and 1 guest