Application Development and Automation 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: 
Read only

How to change string time format to timestamp

Former Member
0 Likes
3,400

Hi Expert,

Do you know how to alter "Tue Mar 30 05:07:35 2010" to timestamp in ABAP, thanks.

Best Regards,

Andrew

Hi Expert,

Do you know how to alter "Tue Mar 30 05:07:35 2010" to timestamp in ABAP, thanks.

Best Regards,

Andrew

7 REPLIES 7
Read only

praveen_hannu
Contributor
0 Likes
3,175

Hi

Use offset for the string, like

 data: time(8),
                     str type string.

string = 'Tue Mar 30 05:07:35 2010'.
time = str+11(8). 

I hope it works, and alter it according to your system settings.

Thanks

Praveen

Read only

Former Member
0 Likes
3,175

Hi,

First you will have to split the string into date and time and then use below function module.

CALL FUNCTION 'IB_CONVERT_INTO_TIMESTAMP'
              EXPORTING
                I_DATLO     = lv_date
                I_TIMLO     = lv_time
              IMPORTING
                E_TIMESTAMP = lt_timestamp.

This function module will give you timestamp.

Thanks,

Archana

Read only

0 Likes
3,175

Hi,

For example, "Tue Mar 30 05:07:35 2010"

It's still difficult to know the month.

Best Regards,

Andrew

Read only

0 Likes
3,175

Use table T247 to get the month.

Read only

0 Likes
3,175

HI

Split this Tue Mar 30 into three variable and collect the Month Name and pass this to T247 Table and get MNR value

Go to T247 table and pass this month and Language as EN you can get the Month Number

Your_Value Tue Mar 30 05:07:35 2010 pass this to a string 
data : str type string.
str = your_value.
day = str+0(3). " Holds Day
mon = str+4(3) " Month
"select single mnr from t247 into Month_no where spras = 'EN' and ktx = mon.
date = str+8(2) " Date
time = str+11(8) " Time
year = str+20(4) " Year.
Concatenate year month_no date time into str. " This gives you Time Stamp.
Check the offsets once again to get the correct value and avoid Short Dumps saying " Invalid Offset

Regards

Ram

Read only

0 Likes
3,175

Hi Andrew,

If your string has fixed format like this then, you can split the string at space into different variables.

string "Tue Mar 30 05:07:35 2010" will be taken into different variables, v_dd, v_mm, v_date, v_time, v_year.

You will have to process variable v_mm, to convert from name to n umber. You can write case for this.

like Case v_mm,

if 'Jan'.

v_month = '1'.

The, concatenate v_dd, v_month, v_year into v_date.

And then call this FM.

Thanks,

Archana

Read only

0 Likes
3,175

data L_LASTCOLLWRT type string value 'Tue Mar 30 08:55:33 2010'.

data ls_mon type t247.

data l_mon type string.

data: time(8),

year(6),

mon(3),

week(3),

day(2).

split L_LASTCOLLWRT at space into week mon day time year.

year = year+0(4).

translate mon to upper case.

data l_input type string.

data l_output type string.

concatenate day mon year into l_input separated by space.

CALL FUNCTION 'CONVERSION_EXIT_IDATE_INPUT'

EXPORTING

INPUT = l_input

IMPORTING

OUTPUT = l_output.

*translate mon to upper case.

replace all occurrences of ':' in time with space.

*select single MNR into l_mon from t247 where SPRAS = sy-LANGU and KTX = mon.

data l_tmp type string.

concatenate l_output time into l_tmp.

*data l_date type DATS.

*data l_time type TimS.

*l_date = data.

*l_time = time.

*concatenate l_date l_time into l_tmp.

write: /, l_tmp.