How to count date difference excluding weekend and holidays?

I should count the number of days between two dates but the weekends and holidays must be excluded from the counting. I used Computed Field.

$start_date_value = array_pop(field_get_items($entity_type, $entity, 'field_date_from'));

$end_date_value = array_pop(field_get_items($entity_type, $entity, 'field_date_to'));

$start_date = new DateObject($start_date_value['value'], '');

$end_date = new DateObject($end_date_value['value'], '');

$entity_field[0]['value'] =$start_date->difference($end_date, 'days');

Here is my working code for counting the days.


why would you try something like this,

create a variable array that contain all the Hollidays

$currentyear=the current year;
$holiday['01-01-'.$currentyear,other holiday,other holiday];

$result=$start_date->difference($end_date, 'days');
    if(holiday[ctr]>=start_date && holiday[ctr]<=end_date)

$result -= temp;
  • Thanks @junnel. I'll try it. But the code is for holidays only. Can you also help me to exclude the weekends in the counting? – noob Apr 24 '14 at 9:48
  • by that i woudl now suggest to create first a function to count the weekdays base on your from_date to end_date befor you go to holliday exclusion – junnel Apr 24 '14 at 9:53

I think you'll find this answer helpful, though it's PHP only:


So you should only need to input your $start_date/$end_date values in correct format and then also define the holidays.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.