Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By sabinsunny
#795823
Hi team,

how to calculate year month and day from two different date in processmaker 3.1

i have two fields 1) date of joining and second one is date of leaving and this function should be triggered after pressing the calculate button
By salman1538
#795826
Hello,

Use below code to get difference:
Code: Select all
$startDate = @@joiningDate;
$endDate = @@leavingDate;
$sDate = strtotime($startDate);
$eDate = strtotime($endDate);
$difference = ($eDate - $sDate) / 86400;   // it will return total no of days 
User avatar
By amosbatto
#795834
You can use salmon1538's PHP code if needing the difference in days in a trigger. If you want the number of whole days, then use this:
Code: Select all
@@difference = (int) (($eDate - $sDate) / 86400);
If you need to calculate the difference in days between two dates in JavaScript, then you can use the following code:
Code: Select all
function calculateDiff(joinDate, leaveDate) {
  if (joinDate == '' || leaveDate == '') {
    $("#difference").setValue('');
  }
  else {
    var daysDiff = moment(leaveDate).diff(moment(joinDate), 'days')
    $("#difference").setValue(daysDiff);
  }
}

$("#joinDate").setOnchange(function(newVal, oldVal) {
  calculateDiff( newVal, $("#leaveDate").getValue() );
});
    
$("#leaveDate").setOnchange(function(newVal, oldVal) {
  calculateDiff( $("#joinDate").getValue(), newVal );
});
In this form:
DifferenceBetweenTwoDates.png
DifferenceBetweenTwoDates.png (8.96 KiB) Viewed 3978 times
Here is the DynaForm to import to try out this code:
(4.56 KiB) Downloaded 311 times
By whoahedi
#822846
Hi amosbatto,
thanks for the answer. I have download your attached form and it works on my workspace.
Still curious, where should I input the given code? I have tried to open the variable / formula / sql but couldn't find where did you put the code.

Im about couple days installing PM :)

A 1xbet clone script is a pre-designed software so[…]

4rabet clone script is enabling entrepreneurs to e[…]

Parimatch clone script is enabling entrepreneurs t[…]

In the world of cryptocurrency, a wallet is an app[…]