Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8184117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:23:25+00:00 2026-06-07T01:23:25+00:00

I am very new to PHP and even more new to CakePHP, which is

  • 0

I am very new to PHP and even more new to CakePHP, which is what my code is writen for but I think my problem is with some of my standard PHP code.

OK, now this code is mostly working but it seems to give me a wrong result when my selected user takes more than one day of at the same time!

OK, so what it is meant to do is to get the years of service for the selected user, it does that OK (i think, no problems at lest). Then from years of service I set sick entitlement, full days and then half days based on years of service.

Once I have done that the code should get the selected users taken sick and with that take off the what they have taken with the entitlement, 1st the full, then when that is empty take it off the half. But like I said when the user takes more than one day off in a row, it still only takes off one day?

It might be where I start my foreach loop and do the count, not sure if that is right?

Please help??

 function sickDay($id = null) {
    if($this->CURRENT_USER['User']['role_id'] > 3) { //directors and admins
    /*if(empty($this->data) || !isset($this->data['Holiday']['id'])) {

    } else {*/
        //Caculate if it's a full pay, half pay or nothing
        //$data = $this->data['Holiday'];

        //Get Holidaytypes
        $types = $this->Holiday->find(
            'all',
            array(
                'conditions' => array(
                    'Holiday.holidaystype_id' => 3,
                    'Holiday.user_id' => $id
                )
            )
        );

        //Get starting date
        $contracts = $this->Holiday->User->Contract->find(
            'all',
            array(
                'conditions' => array(
                    'Contract.user_id' => $id //$data['user_id']
                ),
                'order' => array(
                    'Contract.startson' => 'ASC'
                )
            )
        );
        //Get How Many sick days
        foreach ($types as $key => $value) {

            $typesDataEnds =  strftime ("%u-%d-%Y", $types[$key]['Holiday']['endson']);
            $typesDataStarts = strftime ("%u-%d-%Y", $types[$key]['Holiday']['startson']);

            $SickTotal = count($typesDataEnds - $typesDataStarts);  
            //echo $SickTotal;

        //Get Contract Start & End Dates
        $start = array_shift($contracts);
        $end = array_pop($contracts);

        $endDate = $end['Contract']['endson'];
        $startDate = $start['Contract']['startson'];

        if (empty($endDate)) {
                $endDate = time('now');
        }
        if (!empty($startDate)) {
            $SortEnd = strftime("%Y", $endDate);
            $SortStart = strftime("%Y", $startDate);
            $YearsService = $SortEnd - $SortStart;

            if ($YearsService <= 1) {
                    $SetFullEntitlement = 5;
                    $SetHalfEntitlement = 5;
                    //echo 'one year';
            } elseif ($YearsService <= 2) {
                    $SetFullEntitlement = 10;
                    $SetHalfEntitlement = 10;
                    //echo 'two years';
            } elseif ($YearsService <= 5) {
                    $SetFullEntitlement = 20;
                    $SetHalfEntitlement = 20;
                    //echo 'up to five years';
            } elseif ($YearsService >= 6) {
                    $SetFullEntitlement = 30;
                    $SetHalfEntitlement = 30;
                    //echo 'five years or more';
            } else {
                    $SetFullEntitlement = 0;
                    $SetHalfEntitlement = 0;
                    //echo 'no sick pay';
            }
        } else {
            $YearsService = 0;
            //echo 'Sorry No Start Date For You Found!';
        }

        while ($SickTotal > 0) {
            if ($SetFullEntitlement != 0) {
                $SetFullEntitlement--;
            } elseif ($SetHalfEntitlement != 0) {
                $SetHalfEntitlement--;
            }
            $SickTotal--;
        }

        echo 'FullPay:';
        echo $SetFullEntitlement;
        echo '<br/><br/>Halfpay:';
        echo $SetHalfEntitlement;

        }

        //debug($SickTotal);
        die();  
        //$this->render('/artists/holidayslist');
    //} //End For if empty check
 } // End for if CURRENT_USER
} //End of Function

Update

I understand what you have said and yes, I do now know %u was wrong to use for what I need it to do. Now I have done what you said but I get back 0 for a selected user, which I know should have two?

foreach ($types as $key => $value) {

    $typesDataEnds =  strtotime($types[$key]['Holiday']['endson']);
    $typesDataStarts = strtotime($types[$key]['Holiday']['startson']);

    //$typesDataEnds =  strftime ("%Y-%m-%d", $types[$key]['Holiday']['endson']);
    //$typesDataStarts = strftime ("%Y-%m-%d", $types[$key]['Holiday']['startson']);

    $sickTotal = floor(($typesDataEnds - $typesDataStarts) / 86400);

    echo 'testing: ';
    debug($sickTotal);

    die();

 does more.....

 } //end

Have I done something wrong?

Many Thanks for the help

Glenn.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:23:26+00:00Added an answer on June 7, 2026 at 1:23 am

    I see three problems in the lines where you calculate the sick days:

    1. You’re formatting the dates before the calculation (and the formatting is wrong, see the docs for the meaning of %u). You need numeric values for the calculation. This should work provided the dates are in a format parseable by strtotime:

      $end = strtotime($types[$key]['Holiday']['endson']);
      $start = strrotime($types[$key]['Holiday']['startson']);
      
    2. Then you try to subtract two strings. That won’t work. But if you use strtotime it does work, because then you’re operating on integers:

      $sickTotal = floor(($end - $start) / 86400);
      // 86400 seconds in a day
      
    3. Do not use count on the result. That’s for arrays and objects, when you pass anything else to it, it returns 1 (which explains the wrong results you’re seeing; you’re passing a string).

    I’ve build a working demo for the calculation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to php. I found some CMS like code for east text
I am very new to PHP and MySql. Is there any method by which
I am VERY new to PHP, I'm currently working on a service, part which
i am relatively new to php and i've encountered a very strange problem. let
I am very very new at PHP and I don't even know JSON. Also,
Please forgive the ignorance, but I'm very new to PHP and I couldn't find
I'm very new to PHP and I have a small task of displaying a
I am very new to php and simplepie. I would like to be able
I'm very new to PHP; and am doing a few sample projects to help
I am very new to programming in general, while reading about PHP I saw

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.