Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A different date problem, I promise

Status
Not open for further replies.

timgerr

IS-IT--Management
Jan 22, 2004
364
US
OK here is 1 for the masses. I was asked to make some logs from a database that houses our ticketing system. We have SLA's (Service level agreements) and have to complete the tickets within a certain amount of time. I have a script that grabs data from the database and I have to see how much time is left on the SLA. I have a date and time that the ticket was opened and I need to compare it to the date and time that the script is run on. BUT.... yes there is a but. But we only track from 8am - 5pm (9 hours) Mon through Fri. Here is the format of the date and time field that the database gives me 2005-02-04 13:32:08.000.
Here is what I have so far:
Code:
$today = date(U);
$database = '2005-02-03 03:58:19';
$old = strtotime("$database");
$calc = $new - $old;
This gives me the difference in seconds and does not take in account the 5 out of 7 days of the week.

I need to see how many hours and minutes the tickets have been open during M - F 8am - 9pm.

Any help would be great.

THANKS
timgerr

-How important does a person have to be before they are considered assissinated instead of just murdered?

 
isn't this just a maths problem? you work out the number of seconds to the next 9pm then from the 8am on the next working day to the earlier of the next 9pm or the ticket end etc.
 
How can you tell what day you are counting??



-How important does a person have to be before they are considered assissinated instead of just murdered?

 
use the date function to return the day of the week.

have a look at the code below. i have not tested it in any way but it looks as though it will work.

Code:
<?
$today = strtotime("2005-02-15 08:50:00");  //note that we have not catered for the value of today being outside the 8-9 rule
$start = strtotime("2005-01-10 12:32:05");
$secsinworkingday = (21-8) * 60 * 60; 
$workingdayinterval = 0;
$counted_elapsed_time = 0;


for ($t=$start; $t<=$today; $t=strtotime("+1 day", $t))
{
	//test value of $t for weekend
	$day = date ("D", $t);   //returns three letter day representation
	if ($day != "Sat" && $day != "Sun")
	{
		$workingdayinterval = $workingdayinterval + 1;  //increment counter
		
	}	//else do nothing
	
}

if ($workingdayinterval > 2)
{
	//can automate all but the first and last day
	$counted_elapsed_time = $counted_elapsed_time +(($workingdayinterval-2) * $secsinworkingday);
}

if ($workingdayinterval > 1)
{ 
	//count the first day and the last day
	//first day first
	$firstday = strtotime(date("Y-m-d 21:00:00", $start)) - $start;
	$lastday = $today - strtotime(date("Y-m-d 08:00:00", $today));
}
else
{
	//only one day so just do a straight subtraction
	$firstday = $today - $start; //nb no validation to ensure that today is after start
}

//compile total elapsed seconds
$counted_elapsed_time = $counted_elapsed_time + $firstday + $lastday;
//print out the results

echo "total time elapsed *in seconds)= $counted_elapsed_time <br>";

?>
 
Thanks you I will play with this.

Timgerr

-How important does a person have to be before they are considered assissinated instead of just murdered?

 
have just noticed that you only track until 17h00 - i had read this as 9 pm somehow. to fix change the secsinday variable to (17-8) *60 * 60
 
Thank you for the information, 1 question (for now)
what does this mean:
Code:
$today = strtotime("2005-02-15 08:50:00");  //note that we have not catered for the value of today being outside the 8-9 rule

Thanks

-How important does a person have to be before they are considered assissinated instead of just murdered?

 
I am sorry, I ment //note that we have not catered for the value of today being outside the 8-9 rule

-How important does a person have to be before they are considered assissinated instead of just murdered?

 
if the report can be run outside of the working day (remember i thought the day ended at 9), then the now function may return a time outside of the working day. you need to establish a business rule to decide whether a report run at 17h30 is equal to a report run at 17h00 or at 08h00 the next morning.

once the business rules are defined you can test the today variable and reset the variable to one of the above options.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top