Amigos. necesito saber si la hora es AM o PM, tengo las hora en un campo caracter ejemplo
23:45
04:50
15:00
16:07
21:08
09:00
10:00
19:00
18:50
asi lo tengo
como saber si es AM o PM
Amigos. necesito saber si la hora es AM o PM, tengo las hora en un campo caracter ejemplo
23:45
04:50
15:00
16:07
21:08
09:00
10:00
19:00
18:50
asi lo tengo
como saber si es AM o PM
Si usas MYSQL o MARIADB, hay convertidores, si no, deberas validar en base a si son las 12:01hasta las 24:00 seria PM, de lo contrario es AM...usa VALUE() para convertirlo en numerico y SUBSTR() para extraerlo, es lo que se me ocurre por los momentos, saludos, gracias... ![]()
Function Main()
*-------
Local cl_time
? Am_Pm("04:45")
? Am_Pm("23:59")
return nil
FUNCTION Am_Pm (cl_time)
RETURN IF( VAL(cl_time) < 12, cl_time + " AM",IF(VAL(cl_time) = 12, cl_time + " PM",cl_time + " PM" ))
gracias
jbrita
In a 24 hour time period you have
12:00 midnight 00:00
12:00 noon 12:00
12:00 midnight 24:00
I have struggled with Am\Pm in my scheduling apps .. for example:
I have a reservation that starts at 10:00 pm ( 22:00 ) and ends at 12:00 (24:00 ) midnight and the next reservation starts at 12:00 (00:00) midnight and ends ( the next day ) at 3:00 am (03:00).
The problem I have in using am\pm is how do you know the value of Midnight ? is it AM or PM and if you use AM for 12 midnight .. what is 12:00 noon AM or PM and as the clock moves .. what is 12:00 midnight ( again ) in the same 24 hour period ? AM or PM.
The problem is if you say Midnight 00:00 is AM and Noon 12:00 is PM what happens in the above example in the 24 hour cycle when you come back around to Midnight again 24:00 .. is 24:00 Am or Pm ?
This issue became a paradox to me on my scheduling form when the user would enter in a clock time of 12:00 and I had a drop down with only AM\PM .. How would I know if 12:00 am was 12 midnight (00:00) or 12 noon (12:00) or 12:00 midnight ( 24:00 ) ?
I had to devise a way to designate 12:00 clock time ( which occurs three times in a 24 hour time period ) so I added two additional options to my Am\PM combobox:
AM
NT ( noon time )
MN ( midnight )
PM
So 12:00 midnight 00:00 = 12:00 am
12:00 noon 12:00 = 12:00 nt ( noon time )
12:00 midnight 24:00 = 12:00 mn ( midnight )
Adding NT and MN to my Am\PM combobox allowed me to properly convert 12:00 clock time to either 00:00, 12:00, 24:00 ... Just curious how you convert 12:00 clock time to AM or PM and how do you know if 12:00 is midnight 00:00 or 24:00 ?
Rick Lipkin
PRUEBA ASI
? AmPm("13:14:00") && Result: 1:14:00 pm
? AmPm("09:15:00") && Result: 09:15:00 am
--------------------------------- Source Code ------------------------------
FUNCTION AmPm
PARAMETERS cl_time
RETURN IF( VAL(cl_time) < 12, cl_time + " am",;
IF( VAL(cl_time) = 12, cl_time + " pm",;
STR(VAL(cl_time) - 12, 2) + SUBSTR(cl_time, 3) + " pm" ))
saludos

Rick,
12:00 does not occur three times in a 24 hour period. It can't be both AM and PM at the same time. Midnight is 12AM and noon is 12PM. 11:59:59 at night is PM. One second later it is 12PM.
See also:
What Do the Abbreviations AM and PM Mean?
https://www.worldtimeserver.com/learn/w ... d-pm-mean/
I will admit is it a little confusing.
James
12:00 midnight   00:00
1:00  am      01:00
2:00  am      02:00
3:00  am      03:00
4:00  am      04:00
5:00  am      05:00
6:00  am      06:00
7:00  am      07:00
8:00  am      08:00
9:00  am      09:00
10:00 am      10:00
11:00 am      11:00
12:00 noon     12:00
1:00  pm      13:00
2:00  pm      14:00
3:00  pm      15:00
4:00  pm      16:00 Â
5:00  pm      17:00
6:00  pm      18:00
7:00  pm      19:00
8:00  pm      20:00
9:00  pm      21:00 Â
10:00 pm      22:00
11:00 pm      23:00
12:00 midnight   24:00Rick,
Well I see that you have a strange chart, which I am guessing that you got from militarytime.com. We humans do have a tendency to make things more complicated than they should be.
As a programmer we have to just fix the illogical to logical and then do the calculation. So, we can just pick one time number (either 00:00 or 24:00) and convert it to the other, then do the calculation.
Lucky for us, both Harbour and xHarbour already have a function to convert military time to AMPM format (jbrita already pointed this out above). It is ampm( cMilitaryTime ). Here are the results:
msgInfo( ampm("24:00") ) // returns 12:00 am
msgInfo( ampm("00:00") ) // returns 12:00 am
So, it doesn't matter which time format you use, it works.
Regards,
James
James Bott wrote:Rick,
Well I see that you have a strange chart, which I am guessing that you got from militarytime.com. We humans do have a tendency to make things more complicated than they should be.
As a programmer we have to just fix the illogical to logical and then do the calculation. So, we can just pick one time number (either 00:00 or 24:00) and convert it to the other, then do the calculation.
Lucky for us, both Harbour and xHarbour already have a function to convert military time to AMPM format (jbrita already pointed this out above). It is ampm( cMilitaryTime ). Here are the results:
msgInfo( ampm("24:00") ) // returns 12:00 am
msgInfo( ampm("00:00") ) // returns 12:00 am
So, it doesn't matter which time format you use, it works.
Regards,
James
James
I get what you are saying .. however, I need to convert clock time am\pm to military time .. and when you have 12:00 am 00:00 and 12:00 pm 24:00 you cannot tell which side of the day you are on .. as in the reservation example
10:00 pm to 12:00 midnight ... is 12 midnight am or pm ? 24:00 or 00:00
and the next reservation starts as the old reservation ends
12:00 midnight ( am or pm ? 00:00 or 24:00 ) to 3:00 am
How do you know what is the military value of 12:00 midnight .. is 12:00 midnight am or pm .. and then how do you convert 12:00 midnight to military time .. is it 00:00 or 24:00 ?
That is why ( see image above ) I added MN to the combobox .. so that the data entry is clear and I knew what side of midnight I was on .. MN or AM .. 24:00 or 00:00
An interesting paradox.
Rick Lipkin
Rick Lipkin wrote:James
I get what you are saying .. however, I need to convert clock time am\pm to military time .. and when you have 12:00 am 00:00 and 12:00 pm 24:00 you cannot tell which side of the day you are on .. as in the reservation example
10:00 pm to 12:00 midnight ... is 12 midnight am or pm ? 24:00 or 00:00
and the next reservation starts as the old reservation ends
12:00 midnight ( am or pm ? 00:00 or 24:00 ) to 3:00 am
How do you know what is the military value of 12:00 midnight .. is 12:00 midnight am or pm .. and then how do you convert 12:00 midnight to military time .. is it 00:00 or 24:00 ?
That is why ( see image above ) I added MN to the combobox .. so that the data entry is clear and I knew what side of midnight I was on .. MN or AM .. 24:00 or 00:00
An interesting paradox.
Rick Lipkin