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

Is there a function module to convert a datetime to a date

Former Member
0 Likes
3,188

Ive got a variable of time datetime and i want it to be displayed as a date. Any suggestions?

Ive got a variable of time datetime and i want it to be displayed as a date. Any suggestions?

3 REPLIES 3
Read only

Former Member
0 Likes
1,797

Hello,

Syntax

CONVERT TIME STAMP time_stamp TIME ZONE tz

INTO [DATE dat] [TIME tim]

[DAYLIGHT SAVING TIME dst].

Addition:

... DAYLIGHT SAVING TIME dst

Effect

This statement interprets a time stamp specified in time_stamp as a UTC reference time, converts it to the local date and local time of the time zone specified in tz and assigns the result to the dat, tim and dst variables. At least one of the two additions DATE or TIME must be specified.

The time_stamp data object must have either the data type TIMESTAMP, or TIMESTAMPL from the ABAP Dictionary and the corresponding ABAP type p of length 8 or p of length 11 with seven fractional portions, and which contains one valid time stamp in short or long form. If time_stamp does not contain a valid time stamp, the content of dat and tim is not changed, and sy-subrc is set to 12.

For tz, a data object of type TIMEZONE from the ABAP Dictionary must be specified, which contains a time zone from the TZONE column of the TTZZ database table in uppercase. If tz is initial, no local time is calculated; instead, dat and tim are assigned to the UTC reference time and sy-subrc is set to 4. If the specified time zone is not found in database table TTZZ, the content of dat and tim remains unchanged and sy-subrc is set to 8. If the rules for the specified time zone are not complete, this results in an untreatable exception.

The return values for dat and tim are of data type d or t. For dat and tim, suitable data objects have to be specified, which the return values can be converted into. If the time stamp in time_stamp is available in long form, then the fractions of seconds in the fractional portions are ignored.

System Fields

sy-subrc Meaning

0 Time stamp was converted into the local time of the specified time zome and assigned to the target fields.

4 Time stamp was assigned to the target fields without conversion into the local time.

8 Time stamp could not be converted since the specified time zone is not available in database table TTZZ.

12 Time stamp could not be converted since time_stamp contains an invalid value.

Addition

... DAYLIGHT SAVING TIME dst

Effect

A dst variable of type c of length 1 must be specified after the optional DAYLIGHT SAVING TIME addition. If the time stamp contained in time_stamp for the time zone specified in tz is in the summer, then dst is set to "X". If it is not, it is set to " " (seit Release 6.20).

Notes

A current UTC time stamp can be created using the GET TIME STAMP statement. The current user-related local time zones can be found in the system field sy-zonlo.

From Release 6.20, it is now possible to use the return value for the summer time in dst to differentiate between duplicate local time specifications that occur when UTC time stamps are converted into local time during the double hour in the changeover between summer and winter time.

Example

For the "BRAZIL" time zone available in database table TTZZ, a shift of -3 hours against the UTC reference time is entered in database table TTZR. The end of the summer time is defined in database table TTZDV as the second Sunday in March at 02:00, which in the year 2003 corresponds to March 9th. With these settings in the rules, the two conversions below both result in the same local time of "01:30:00". The first conversion shows that the time is still in the summer time (from Release 6.20).

DATA: time_stamp TYPE timestamp,

dat TYPE d,

dat TYPE d,

tz TYPE ttzz-tzone,

dst TYPE c LENGTH 1.

tz = 'BRAZIL'.

time_stamp = 20030309033000.

CONVERT TIME STAMP time_stamp TIME ZONE tz

INTO DATE dat TIME tim DAYLIGHT SAVING TIME dst.

WRITE: /(10) dat, (8) tim, dst.

time_stamp = 20030309043000.

CONVERT TIME STAMP time_stamp TIME ZONE tz

INTO DATE dat TIME tim DAYLIGHT SAVING TIME dst.

WRITE: /(10) dat, (8) tim, dst.

Regards.

Read only

Former Member
0 Likes
1,797

Hi,

If it is TIMESTAMP, you can use

CONVERT TIMESTAP <timestamp> TO DATE <w_date>

TIME <w_time>

Thanks and Regards,

Lakshmi.

Read only

Former Member
0 Likes
1,797

Hi,

check the FM "FRE_CONVERT_TIMESTAMP_2_DATE" & IB_CONVERT_FROM_TIMESTAMP.

Regards

Kiran Sure