CDS中的日期和时间
$session.system_date
$session.system_date 系统时间,SY-DATUM
TSTMP_CURRENT_UTCTIMESTAMP( )
TSTMP_CURRENT_UTCTIMESTAMP( )取得当前时间戳;
tstmp_current_utctimestamp() as Time3,//当前时间戳
substring(cast(tstmp_current_utctimestamp()as abap.char(17)),1,8)as Time1,//当前日期
substring(cast(tstmp_current_utctimestamp()as abap.char(17)),9,6)as Time2,//当前时间
使用需要注意时区问题
日期/时间转换的SQL函数目前只能在Core Data Service中使用,OPEN SQL不能使用。
· TSTMP_TO_DATS( tstmp, tzone, clnt, on_error )将时间戳的日期部分转为d类型
· TSTMP_TO_TIMS( tstmp, tzone, clnt, on_error )将时间戳的时间部分转换为t类型
· DATS_TIMS_TO_TSTMP( date, time, tzone, clnt, on_error )将日期和时间拼成时间戳
· ABAP_SYSTEM_TIMEZONE( clnt, on_error )取得系统时区
· ABAP_USER_TIMEZONE( user, clnt, on_error )取得用户主数据的时区
举例:
@AbapCatalog.sqlViewName: 'demo_cds_datim'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_date_time
as select from
demo_expressions
{
tstmp_current_utctimestamp() as tstmp,
tstmp_to_dats( tstmp_current_utctimestamp(),
abap_system_timezone( $session.client,'NULL' ),
$session.client,
'NULL' ) as dat,
tstmp_to_tims( tstmp_current_utctimestamp(),
abap_system_timezone( $session.client,'NULL' ),
$session.client,
'NULL' ) as tim,
tstmp_to_dst( tstmp_current_utctimestamp(),
abap_system_timezone( $session.client,'NULL' ),
$session.client,
'NULL' ) as dst,
dats_tims_to_tstmp( dats1,
tims1,
abap_system_timezone( $session.client,'NULL' ),
$session.client,
'NULL' ) as dat_tim
}
取年月日时分秒
concat(
cast( $session.system_date as abap.char(8) ),
cast( tstmp_to_tims( tstmp_current_utctimestamp(), //取得时间戳
//abap_system_timezone( $session.client,'NULL'),//取得系统时区
'UTC+8',
$session.client,
'NULL')as abap.char(6) )
) as Time, //时间
2021年08月12日11时34分54秒