• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Date calculation

Date calculation 15 years 4 months ago #6178

I need to do a vacances employee form, that could register the user data.
In this form, i´ve a two fields with date format, like Start Date and End Date.

I want to calculate the number of days between start date and End date, but i want exclude the weekends (saturday and sunday).

I can i do this?
Can you give me some advice for this case?
The administrator has disabled public write access.

Re:Date calculation 15 years 3 months ago #6404

I'm after the same info as well
The administrator has disabled public write access.

Re:Date calculation 15 years 3 months ago #6444

  • covareo
  • covareo's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 2
fernando.m.mendes wrote:
I need to do a vacances employee form, that could register the user data.
In this form, i´ve a two fields with date format, like Start Date and End Date.

I want to calculate the number of days between start date and End date, but i want exclude the weekends (saturday and sunday).

I can i do this?
Can you give me some advice for this case?

Is this what you need?
<?php
        function calculateWorkingDays($fromDate,$tillDate) {
            $arrDatumRange = range(
                strtotime($fromDate) ,
                strtotime($tillDate) ,
                (3600*24)
            );
            foreach ($arrDatumRange as $key=>$iTime) {
                if (date("N",$iTime) != 6 && date("N",$iTime) != 7) {
                    $arrDatumRange[$key] = date("j-n-Y",$iTime);
                } else {
                    unset ($arrDatumRange[$key]);
                }
            }
            return $arrDatumRange;
        }
 
// Example:
$arrWorkingDayDates = calculateWorkingDays("20-1-2009","19-4-2009");
?>

Found here: http://us3.php.net/date
The administrator has disabled public write access.

Re:Date calculation 15 years 3 months ago #6445

  • covareo
  • covareo's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 2
Another function from that same page:
<?php
function getNoWorkingDays()
 
    {
 
    $days_in_month = date('t');
 
    $noofwokingdays=0;
 
 
    for ($j=0; $j<$days_in_month; $j++)
    {
 
    $d = $j + 1;
    $my = date('m-Y');
    $day_of_week = date('w', strtotime("$d-$my", 0));
    if ( $day_of_week == 6 || $day_of_week == 0)
        {
 
        $noofwokingdays=$noofwokingdays;
 
        }
    else
        {
        $noofwokingdays++;
        }
 
    }
 
    return $noofwokingdays;
 
    }
?>
The administrator has disabled public write access.

Re:Date calculation 15 years 2 months ago #6727

Where should I put these code?
The administrator has disabled public write access.

Re:Date calculation 14 years 11 months ago #7443

Someone solved this problem?
I really need help in this one.
Thanks
Found another code but can’t put it to work

<?php
/**
 * Finds the difference in days between two calendar dates.
 *
 * @param Date $startDate
 * @param Date $endDate
 * @return Int
 */
function dateDiff($startDate, $endDate)
{
    // Parse dates for conversion
    $startArry = date_parse($startDate);
    $endArry = date_parse($endDate);
 
    // Convert dates to Julian Days
    $start_date = gregoriantojd($startArry["month"], $startArry["day"], $startArry["year"]);
    $end_date = gregoriantojd($endArry["month"], $endArry["day"], $endArry["year"]);
 
    // Return difference
    return round(($end_date - $start_date), 0);
}
?>
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!