Salesforce Apex Code Calculate Difference Hours

public static Integer calculateDateDifferenceHours(Datetime date1, Datetime date2) {
        Long dtStartLong = date1.getTime();
        Long dtEndLong = date2.getTime();
        Long milliseconds = (dtEndLong - dtStartLong);
        Long seconds = milliseconds / 1000;
        Long minutes = seconds / 60;
        Long hours = minutes / 60;
        Long days = hours / 24;
        return Integer.valueOf(hours);
    }

Leave a Reply

en English
en Englishfr Frenchde Germanit Italian