To glue date and time to a timestamp or to split a timestamp into date and time it is possible to do this in a various ways. (By "glue" I mean to create a timestamp out of a date and a time so the time zone stays the same and by "split" I mean to split up a timestamp so a date and a time is created with the same time zone; So this blog concentrates on no time zones...if you need time zone conversion, you have to use CONVERT) I show which one takes which time.
From date and time to a timestamp
via convert date time
via concatenate
via char modification (1)
via char modification (2)
via structure
Comparison of the different types
And now for the comparison of the different types of date and time to timestamp conversions I measured these times:
conversion type | time consumed (no real times) |
---|
convert date time | 21227 |
concatenate | 2957 |
char modification (1) | 2599 |
char modification (2) | 2727 |
structure | 2594 |
So this means that we should go for the "char modification (1)" or the "structure" conversion. But what this also means is, that the CONVERT DATE TIME INTO TIME STAMP TIME ZONE is a very very bad idea. Never use CONVERT! So either do something like thislv_char14(8) = sy-datum.
lv_char14+8(6) = sy-uzeit.
or something like thistypes:
begin of datetimestr,
datum type sydatum,
uzeit type syuzeit,
end of datetimestr.
ls_datetimestr-datum = sy-datum.
ls_datetimestr-uzeit = sy-uzeit.
From timestamp to date and time
To do the split from timestamp to date and time, you can use nearly the same options as above: convert time stamp, char modifications and the structure thing.
via convert time stamp
via char modification
via structure
Comparison of the different types
And now for the comparison of the different types of timestamp to date and time conversions I measured these times:
conversion type | time consumed (no real times) |
---|
convert date time | 16250 |
char modification | 10665 |
structure | 10287 |
So this means that we should go for the "char modification (1)" or the "structure" conversion (the difference is not really big). And again never use CONVERT, it is not this bad in this example, but it is bad enough. So either do something like thislv_datum = lv_char14(8).
lv_uzeit = lv_char14+8(6).
or something like thistypes:
begin of datetimestr,
datum type sydatum,
uzeit type syuzeit,
end of datetimestr.
ls_datetimestr = lv_timestamp.
lv_datum = lv_datetimestr-datum.
lv_uzeit = ls_datetimestr-uzeit.
Code for the measurement
And finally here is the code I used to measure the times (the naming in the coding is different):
(use this to copy and paste in a test report)
...and something at the end on the CONVERT which has nothing to do with performance: please remember that the TIME ZONE is always related to the DATE and TIME parts. The TIME STAMP is always always always in UTC. There is no possibility that you can convert to or from a non-UTC timestamp with CONVERT!