Page 1 of 1
Saber si es AM o PM * SOLUCIONADO *
Posted: Mon Sep 25, 2017 9:44 pm
by jbrita
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
Re: Saber si es AMP o PM
Posted: Mon Sep 25, 2017 9:51 pm
by joseluisysturiz
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...
http://mysql.conclase.net/curso/?sqlfun=DATE_FORMAT
https://dev.mysql.com/doc/refman/5.7/en ... ate-format
Re: Saber si es AM o PM * SOLUCIONADO *
Posted: Tue Sep 26, 2017 12:29 am
by jbrita
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
Re: Saber si es AM o PM * SOLUCIONADO *
Posted: Tue Sep 26, 2017 1:12 pm
by Rick Lipkin
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
Re: Saber si es AM o PM * SOLUCIONADO *
Posted: Tue Sep 26, 2017 1:17 pm
by jbrita
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
Re: Saber si es AM o PM * SOLUCIONADO *
Posted: Tue Sep 26, 2017 1:29 pm
by Rick Lipkin
jbrita
In your example .. what is 24:00 .. AM or PM
what is 12:00 .. AM or PM
what is 00:00 .. AM or PM
I want to schedule a trip to start at 11:00pm ( 23:00 ) and end at 12:00 midnight ... is 12:00 clock time AM or PM since 12:00 occurs three times in a 24 hour period ?
Rick Lipkin
Re: Saber si es AM o PM * SOLUCIONADO *
Posted: Wed Sep 27, 2017 2:47 pm
by James Bott
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
Re: Saber si es AM o PM * SOLUCIONADO *
Posted: Wed Sep 27, 2017 6:18 pm
by Rick Lipkin
James
Here is the Military time conversion ..
Code: Select all
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:00
Consider the above image .. and time line
You have a reservation from 11:00 pm to 12 midnight .. and the next reservation starts promptly at 12:00 midnight to 3:00am .. how do you convert the time line 'clock time' to 'military time' ?
23:00 to 24:00
00:00 to 03:00
The above is the only solution... with Midnight occurring twice and noon once .. in a single 24 hour period.
Rick Lipkin
Re: Saber si es AM o PM * SOLUCIONADO *
Posted: Wed Sep 27, 2017 10:51 pm
by James Bott
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
Re: Saber si es AM o PM * SOLUCIONADO *
Posted: Thu Sep 28, 2017 3:02 am
by joseluisysturiz
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
...y nosotros inventando la rueda...gracias James, saludos...
Re: Saber si es AM o PM * SOLUCIONADO *
Posted: Thu Sep 28, 2017 1:02 pm
by Rick Lipkin
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
Re: Saber si es AM o PM * SOLUCIONADO *
Posted: Fri Sep 29, 2017 2:32 pm
by hebert_j_vargas
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
Rick I think in Military format, 24:00 represent the end of the day so the answer is 12:00 MIDNIGHT, 00:00 is the start of the day so it should be 12:00 A.M., and 12:00 Sharp is 12:00 MIDDAY or MERIDIAM.