Jump to content

Recommended Posts

Thanks for the answers.

 

Well i have a table like below -->

 

ticket id      receive time                    submit time                  sla (service level agreement)

112121      2009-06-14 13:29:55      2009-06-14 13:29:55

 

 

a request comes in and a ticket is being created. The time of the request is the receive time and the ticket creation time is the submit time. The diffrence between them can be max. 120min. So for each request you have to create a ticket within 120min. The receive time is being entered manually(copy paste). The submit time is the time where the employee submits the ticket in his tool. The submit time is automatically generated when he clicks submit which takes the current timestamp like the format above. I just have to calculate the sla for each entry which doesnt work now.

I tried your suggestion with now() but it gives me a strange time when i type echo now() ; --->

 

1244980096

 

Link to comment
https://forums.phpfreaks.com/topic/162032-solved-time-diff/#findComment-855552
Share on other sites

if by now() you mean time(), that's called a unix timestamp.  It's a numeric representation of time, in seconds, since the unix epoch.  You would convert your time strings into their timestamps and subtract. The result would be in seconds, so you would want to divide by 60 to get minutes.

Link to comment
https://forums.phpfreaks.com/topic/162032-solved-time-diff/#findComment-855575
Share on other sites

dateA  2009-06-14 17:00

dateB  2009-06-14 17:50

 

So if i understand you right, to find the time diffrence in minutes between dateB and dateB, i have to convert both timestamps into unix timestamp and divide through 60.

 

I am a little bit confused can you please explain me in details with an example?

 

Thanks...

Link to comment
https://forums.phpfreaks.com/topic/162032-solved-time-diff/#findComment-855606
Share on other sites

You mostly understood right.

 

okay to be clear: "2009-06-14 17:50" is not a timestamp.  It is a string that represents the date, that is readable by humans.  As far as php (or computers in general) is concerned, it's just some arbitrary string.  Computers keep track of time via timestamps.  And a timestamp is that long number, which is the number of seconds since the unix epoch. 

 

So if you want to find out the number of minutes between two strings that you interpret as a date/time, you would first convert them into their timestamp equivalent so php can understand it.  Then subtract the two.  The result would be the difference in seconds.  Since you want it to be in minutes, you would then divide by 60, since there are 60 seconds in a minute.  So for your example times, you would do this:

 

edit: woops, accidentally hit post instead of preview... example:

 

$dateA = strtotime('2009-06-14 17:00');
$dateB = strtotime('2009-06-14 17:50');

$diff = ($dateB - $dateA) / 60;
echo $diff . " minutes difference";

 

I'd also like to just throw out there that if both of these date/times are in sql, you can have sql perform these operations and just return you the difference.  Not really sure about your setup though, so that may not be applicable.

Link to comment
https://forums.phpfreaks.com/topic/162032-solved-time-diff/#findComment-855611
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.