In the course of implementing a business requirement, I recently had to calculate the difference between two DateTime fields in SAP C4C for reporting which calculates ticket assignment time from the creation. However, I couldn’t find any straightforward blog that provided a simple solution to this problem.

Fortunately, SAP provides a function called Delta() that can be used to calculate the difference between two DateTime fields. The only catch is that Delta() is only accessible for the GlobalDateTime data type.

So, how can you use Delta() for DateTime fields? It’s simple – just use the ConvertToGlobalDateTime() function after your DateTime field. This will convert your DateTime field to GlobalDateTime format, allowing you to use Delta().

The result of Delta() is returned in a “Duration” format, which was not convenient for my purposes. To convert the result into minutes or hours, I simply used the ConvertToMinutes() / ConvertToHour() functions, respectively.

Here’s a code snippet that demonstrates how to use Delta() to calculate the difference between two DateTime fields:

// Creation time in Datetime format.
var ZV_CreationDateTime = this.RequestInitialReceiptTimePoint.TimePoint.DateTime; 


//Converting local datetime to global datetime to use standard Delta function.
var ZV_CreationDateTimeGlobal = Library::DateTime.ConvertToGlobalDateTime(ZV_CreationDateTime);


//Ticket reassigned datetime.
var ZV_AssignedDateTime = Context.GetCurrentGlobalDateTime(); 


//Calculating the difference between two dates.
var ZV_DeltaDifference = ZV_AssignedDateTime.Delta(ZV_CreationDateTimeGlobal).ConvertToMinutes();
I hope this solution helps you as much as it helped me. If you have any feedback or questions, please don’t hesitate to leave a comment.

Best regards,

Pratik Shekokar

SAP C4C Technical Consultant

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x