06-01-2011 10:34 AM
HI
I have used sy-uzeit to get the system time but i want the time to displayed in AM or PM
for eg: 02:30:56 PM
Can anybody please suggest how to do this..
06-01-2011 10:43 AM
try this:
data: lv_time like sy-uzeit.
lv_time = sy-uzeit.
if lv_time+0(2) >= 12.
if lv_time+0(2) > 12.
lv_time0(2) = lv_time0(2) - 12.
endif.
write: / lv_time, 'PM'.
else.
write: / lv_time, 'AM'.
endif.
06-01-2011 11:22 AM
06-01-2011 11:35 AM
Hi Vani,
No need to do the above you can still achieve the same using the write to ABAP construct as shown below,
Also I am not sure if the above suggestions would work in a system where the time format is set to 12 hour.
DATA: l_char TYPE char20.
SET COUNTRY 'IN'.
WRITE sy-uzeit TO l_char ENVIRONMENT TIME FORMAT.
WRITE l_char.
IF sy-subrc EQ 0.
ENDIF.
Note: You need to check the country setting in table T005X for the country in concern, the field "TIMEFM" must have the value either of the value as per your need.
1 12 Hour Format (Example: 12:05:10 PM)
2 12 Hour Format (Example: 12:05:10 pm)
Regards,
Chen
Edited by: Chen K V on Jun 1, 2011 4:07 PM
06-01-2011 11:55 AM
06-01-2011 12:03 PM
06-01-2011 12:07 PM
Hi.,
There is no FM for this., You can create one for your requirement., with importing parameter time and exporting parameter local_time.
and do the same code inside FM . pass time as sy-uzeit and get the converted time..
hope this helps u.,
Thanks & Regards,
Kiran
06-01-2011 12:19 PM
You can use method CONV_TIME_INT_TO_EXT of class CL_ABAP_TIMEFM, but i don't know any such FM, so code will become
SET COUNTRY 'IN'.
cl_abap_timefm=>conv_time_int_to_ext(
exporting
time_int = l_time
format_according_to = cl_abap_timefm=>environment
importing
time_ext = l_ctime ).
SET COUNTRY space.
Check also time format documentation at [format_options ... TIME = RAW ISO USER ENVIRONMENT (val)|http://help.sap.com/abapdocu_702/en/abapcompute_string_format_options.htm#!ABAP_ADDITION_13@13@]
Regards,
Raymond
06-01-2011 10:49 AM
Hi.,
You have to do it manually by code., try this.,
DATA: time TYPE string,
hrs type char10.
time = sy-uzeit.
IF time+0(2) ge 12.
hrs = time+0(2) - 12.
CONCATENATE hrs time2(2) time4(2) INTO time SEPARATED BY ':'.
CONCATENATE time 'PM' INTO time SEPARATED BY ''.
ELSE.
CONCATENATE time0(2) time2(2) time+4(2) INTO time SEPARATED BY ':'.
CONCATENATE time 'AM' INTO time SEPARATED BY ''.
ENDIF.
WRITE time.
hope this helps u.,
Thanks & Regards,
Kiran
06-01-2011 11:39 AM