Skip to main content
Edited directly into your code
Source Link
Gregory Kapustin
  • 2.2k
  • 1
  • 15
  • 26

I would :

  1. Check if there's a weekend between $start and $end :

    if($start_date->format('W') != $end_date->format('W'))

  2. Then substract 48 hours for each week of difference.

    $difweeks = intval($start_date->format('W') - $end_date->format('W'));

    $duration = $duration - intval(48 * $difweeks);

$duration = $start_date->difference($end_date, 'hours');
// Place this :
if($start_date->format('Y-W') != $end_date->format('Y-W')) {
  $difweeks = $start_date->difference($end_date, 'weeks');
  $duration = $duration - intval(48 * $difweeks);
}
$entity_field[0]['value'] = $duration;

I would :

  1. Check if there's a weekend between $start and $end :

    if($start_date->format('W') != $end_date->format('W'))

  2. Then substract 48 hours for each week of difference.

    $difweeks = intval($start_date->format('W') - $end_date->format('W'));

    $duration = $duration - intval(48 * $difweeks);

I would :

$duration = $start_date->difference($end_date, 'hours');
// Place this :
if($start_date->format('Y-W') != $end_date->format('Y-W')) {
  $difweeks = $start_date->difference($end_date, 'weeks');
  $duration = $duration - intval(48 * $difweeks);
}
$entity_field[0]['value'] = $duration;
added 8 characters in body
Source Link
Gregory Kapustin
  • 2.2k
  • 1
  • 15
  • 26

I would :

  1. Check if there's a weekend between $start and $end :

    if($start_date->format('W') != $end_date->format('W'))

  2. Then substract 48 hours for each week of difference.

    $difweeks = $start_dateintval($start_date->format('W') !=- $end_date->format('W'));

    $duration = $duration - intval(48 * $difweeks);

I would :

  1. Check if there's a weekend between $start and $end :

    if($start_date->format('W') != $end_date->format('W'))

  2. Then substract 48 hours for each week of difference.

    $difweeks = $start_date->format('W') != $end_date->format('W')

    $duration = $duration - intval(48 * $difweeks);

I would :

  1. Check if there's a weekend between $start and $end :

    if($start_date->format('W') != $end_date->format('W'))

  2. Then substract 48 hours for each week of difference.

    $difweeks = intval($start_date->format('W') - $end_date->format('W'));

    $duration = $duration - intval(48 * $difweeks);

Source Link
Gregory Kapustin
  • 2.2k
  • 1
  • 15
  • 26

I would :

  1. Check if there's a weekend between $start and $end :

    if($start_date->format('W') != $end_date->format('W'))

  2. Then substract 48 hours for each week of difference.

    $difweeks = $start_date->format('W') != $end_date->format('W')

    $duration = $duration - intval(48 * $difweeks);