Sometimes the operating system will calculate the timestamp of a file or directory with the number of seconds that have passed. Great stuff or course, but how do you calculate with that ? Can it be converted into a date and time again ? Of course it can.
Calculate the number of seconds that have passed since 1st of January 1970:
constants:
co_1970 type d value '19700101',
co_seconds_in_day(6) type p value 86400, " = 24 * 60 * 60
co_seconds_in_hour type p value 3600. " = 60 * 60
data: lv_now TYPE t,
lv_seconds_since_1970(6) type p decimals 0,
lv_age type i.
lv_age = 0. "Age in days - to select files older than n days
lv_seconds_since_1970 = ( ( ( sy-datum - co_1970 ) - lv_age ) * co_seconds_in_day ) +
( lv_now(2) * co_seconds_in_hour ) +
( lv_now+2(2) * 60 ) +
( lv_now+4(2) ).
Transform into a date and time
The AL11 transaction has a bit of coding in place to perform this task - which I relied upon before. Calculating a number of seconds that passed between 2 dates is a lot easier than the other way around, so you may want to use this:
data: lv_time type c length 8, "Note: not returned as type T but preformatted 12:00:23
lv_date type d.
* Copied from an AL11 call:
perform p6_to_date_time_tz in program rstr0400 using
lv_seconds_since_1970 lv_time lv_date.
