2014 Mar 17 12:38 PM
Dear experts,
I would like to convert a timestamp to a date and time within a CDS view.
This is what I tried to do:
Cast (Cast(<timestamp> as abap.dec(8,0)) as abap.dats) as <date>
I also thought about first converting the timestamp into a plain numerical character, then using substring and then casting it to abap.dats. Then its giving me an error that says: "dec can't be converted into numc".
The above written code also throws an error - "function not allowed/ no cast within a cast".
It is quite nasty not being able to write a cast within a cast - how else am i supposed to achieve a date here?
I am looking forward to have your answers!
Thanks and BR
Anja
2014 Mar 17 2:36 PM
Hi Anja,
what you try to do is currently not possible, a feature not available in CDS views.
Yet it surely is a feature, ABAP developers would like to see on the feature request list .
Cheers,
Jasmin
2014 Mar 17 2:36 PM
Hi Anja,
what you try to do is currently not possible, a feature not available in CDS views.
Yet it surely is a feature, ABAP developers would like to see on the feature request list .
Cheers,
Jasmin
2015 Dec 28 12:00 PM
Hi Anja,
Yon can try like this.
cast(substring(cast(creationdatetime as abap.char(32)),1,8) as abap.dats) as creationdate
Regards,
Chandru.
2015 Dec 28 2:30 PM
Please note that timestamp is considered to be UTC and date is usually your local date, so a time zone specification is necessary for a proper conversion, see for instance ABAP-doc for statement "CONVERT TIME STAMP ..."; and then it is impossible to get the correct result using any combination of cast and substring or the like.
2016 Jun 17 4:27 PM
There is now a function you can use in CDS views:
tstmp_to_dats( timestamp,
abap_system_timezone( $session.client,'NULL' ),
$session.client,
'NULL' ) as cpudt,
Also there's a vration tstmp_to_tims to get a TIMS value.
I'm seeing this on a NW 752 release; not sure when it became available...
Jim
2016 Jul 15 6:21 PM
Thanks Jim! Have you found this in documentation anywhere? I've been unable and was hoping to track down which release we'd need.
2020 Apr 17 10:42 PM
2023 Jan 18 1:07 AM
2023 Aug 18 5:40 PM
cast(Left(cast(case_attr.create_time as abap.char(20)), 15) as abap.dats ) as create_date,
case_attr is table alias
create_time is field name
create date is final date separated from timestamp
Thanks