Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

To get system time in AM PM

Former Member
0 Kudos

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..

9 REPLIES 9

Former Member
0 Kudos

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.

0 Kudos

Thank u for ur suggestion.

0 Kudos

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

0 Kudos

Hi

Is there any standard function module to achieve this..?

0 Kudos

I wasn't able to find any

Regards,

Chen

0 Kudos

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

0 Kudos

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

former_member184578
Active Contributor
0 Kudos

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

0 Kudos

Thank u .

its working.