How to Calculate the Difference Between Two DateTime Fields in SAP C4C
source link: https://blogs.sap.com/2023/04/05/how-to-calculate-the-difference-between-two-datetime-fields-in-sap-c4c/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to Calculate the Difference Between Two DateTime Fields in SAP C4C
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();
Best regards,
Pratik Shekokar
SAP C4C Technical Consultant
Recommend
-
117
DateTimePeriod An implementation of the datetime period type for working with temporal intervals. The library includes the full set of relations on intervals defined by
-
151
Carbon An international PHP extension for DateTime. https://carbon.nesbot.com <?php use Carbon\Carbon; printf("Right now is %s", Carbon::now()->toDateTimeStri...
-
81
Carbon A simple PHP API extension for DateTime. http://carbon.nesbot.com use Carbon\Carbon; printf("Right now is %s", Carbon::now()->toDateTimeString()); printf("R...
-
82
How do I get the current time in Python? The time module The time module provides functions that tell us the time in "seconds since the epoch" as well as other utilities.
-
4
Avoid the pitfall of between and until There are some use cases that require to count the number of days between two dates. For example you need to count the days between the 1st of January 2019 and the 31t...
-
5
Calculate the hours between two date / time strings (YYYY-MM-DD HH: MM: SS) using Javascript advertisements I have two Time Stamps in the foll...
-
2
How to calculate the angle between two directional vectors which form a closed / open form? advertisements I am trying to f...
-
1
Community As companies calculate cyber risk, the right data makes a big difference
-
4
C program to calculate the angle between hour and minute handSkip to content
-
2
Fastest way to calculate distance between coordinates I’m always facing the problem of...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK