In SAP ABAP, you can get the current date and current time using system variables. Here are different ways to retrieve them:
1. Using System Variables (SY-DATUM & SY-UZEIT)
DATA: lv_date TYPE sy-datum, lv_time TYPE sy-uzeit.
lv_date = sy-datum. " Current date (YYYYMMDD)lv_time = sy-uzeit. " Current time (HHMMSS)
WRITE: 'Current Date:', lv_date, 'Current Time:', lv_time.✅ Simple and recommended for most cases
✅ SY-DATUM stores date in YYYYMMDD format
✅ SY-UZEIT stores time in HHMMSS format
2. Get Current Date and Time as a Timestamp (SY-TIMESTAMP)
DATA: lv_timestamp TYPE timestamp.
lv_timestamp = sy-timestamp. " Current timestamp (YYYYMMDDHHMMSS)
WRITE: 'Current Timestamp:', lv_timestamp.✅ Best when you need both date and time in a single field
✅ Format: YYYYMMDDHHMMSS (14 digits)
3. Using GET TIME STAMP Statement
If you need a precise UTC timestamp, use:
DATA: lv_timestamp TYPE timestamp.
GET TIME STAMP FIELD lv_timestamp.
WRITE: 'Current UTC Timestamp:', lv_timestamp.✅ More accurate than SY-TIMESTAMP
✅ Uses Coordinated Universal Time (UTC)
4. Using Function Module GET_TIME (Alternative)
DATA: lv_date TYPE sy-datum, lv_time TYPE sy-uzeit.
CALL FUNCTION 'GET_TIME' IMPORTING date = lv_date time = lv_time.
WRITE: 'Date:', lv_date, 'Time:', lv_time.✅ Alternative method but rarely needed
✅ Similar output as SY-DATUM & SY-UZEIT
Best Method to Use?
| Scenario | Recommended Method |
|---|---|
| Get current date | SY-DATUM |
| Get current time | SY-UZEIT |
| Get date & time together | SY-TIMESTAMP |
| Get UTC timestamp | GET TIME STAMP |
| Alternative approach | GET_TIME function |