Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member625898
Participant


Hello everyone,

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
Labels in this area