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 9289271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:08:11+00:00 2026-06-18T20:08:11+00:00

I am doing resource allocation for an event. My event table for one resource

  • 0

I am doing resource allocation for an event.

My event table for one resource is looks like this:

(Int)---(nvarchar(100)---(datetime)--(datetime)

EventId --- Event ---    StartTime ---              EndTime

1    /       test    /    2013-02-20 13:00:00   /   2013-02-20 15:00:00

2    /       test2   /     2013-02-20 09:30:00  /   2013-02-20 11:00:00

3    /       test3   /     2013-02-25 11:30:00  /   2013-02-25 14:30:00

Now I want to find the total availablity for this resource on one day.

Like on 20th Feb 2013 I want to remove the busy hours from this resource and want to show only available hours for new event.

I am using php and sql server 2008 r2.

It works fine with only one record of a single day. Right now I am using a foreach loop with calculation.

My Code is:

$id = 6;    
$cdata = $test->getResourceEvents($id);

$h = "";
$final= array();

foreach($cdata as $c)
   {

   $sh = $c['starttime']->Format('H'); // Starting hour
   $eh = $c['endtime']->Format('H'); // End hour

   $hh = $sh;
   $final = array();
   $sdate = $c['starttime']->Format('Y-m-d');
   $edate = $c['endtime']->Format('Y-m-d');
   if($edate == $sdate)
   {

   $dh = $eh-$sh; // Duration
       for($i=1;$i<=$dh;$i++)
       {
           $hh = $hh.",".($sh+$i); // Busy hours
       }    
   $busyhrs[$sdate] = explode(",",$hh);
       $final[$sdate] = $busyhrs;
   }
   else
   {
       echo "false";
   }
}

print_r($final);

and my result is :

Array
(
    [2013-02-20] => Array
        (
            [2013-02-20] => Array
                (
                    [0] => 9
                    [1] => 10
                    [2] => 11
                )

        )

    [2013-02-26] => Array
        (
            [2013-02-26] => Array
                (
                    [0] => 11
                    [1] => 12
                    [2] => 13
                    [3] => 14
                )

        )

)

First two records have the same dates. but this only calculates 2nd row’s hours. Not calculating first row’s hours that is 13,14,15.

Can anyone please tell me how to match the dates and how to get total busy hours of one date?

  • 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-18T20:08:13+00:00Added an answer on June 18, 2026 at 8:08 pm

    I found the solution.
    I changed the process of making final array.
    Thanks a lot to all for helping me.
    I think its simple.
    Here is my code.

    May be it will be helpful to someone.

            $id = 6;    
            $cdata = $test->getResourceEvents($id);
    
            $h = "";
            $final= array();
    
            foreach($cdata as $c)
            {
                $sh = $c['starttime']->Format('H'); // Starting hour
    
                $eh = $c['endtime']->Format('H'); // End hour
    
    
                $hh = $sh;
                $busyhrs = array();
                $sdate = $c['starttime']->Format('Y-m-d');
                $edate = $c['endtime']->Format('Y-m-d');
                if($edate == $sdate)
                {
                    $dh = $eh-$sh; // Duration
                    for($i=1;$i<=$dh;$i++)
                    {
                        $hh = $hh.",".($sh+$i); // Busy hours
                    }   
    
                    if($final != array() || $final != NULL)
                    {
                        foreach($final as $key=>$val)
                        {
                            if($key==$sdate)
                            {
                                $final[$key] = $val.",".$hh;
                            }
                            else
                            {
                                $final[$sdate] = $hh;
                            }
                        }
                    }
                    else
                    {
                        $final[$sdate] = $hh;
                    }                           
                }
                else
                {
                    echo "false";
                }
            }
    
            echo "<pre>";
            print_r($final);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Feel like I'm doing this right, but apparently not. I have a restful resource,
I am doing something like: $outputFile = getCurrentDBSnapshot($data); where $data is the resource stream
I'm doing this : WebResource resource = client.resource(urlStr); resource.accept(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE); GenericType<List<EMailInformations>> genericType = new
This is a resource-allocation problem. My goal is to run a query to fetch
I am doing resource allocation on certain events. I am using resource view, so
Doing the getting started of Sinatra. I get this error: ./sinatra.rb:5: undefined method `get'
I have some resource which I'd like to protect from concurrent usage both by
I have a dimension resource setup in my res/dimens.xml like so: <dimen name=cornerRadius>40.0dp</dimen> However,
Doing some initial research on a new project and one of my requirements is
I tried doing it with this code: et.setText(sb.getProgress()); where et is the EditText and

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.