Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. Get the time differance??

hi i have problem that getting time differance

if \$b2=18:02:15

\$b3=18:05:15

Im not getting the correct time different as 3 min

\$b2=date("H:i:s", \$barcodetime);

\$b3=date("H:i:s", \$Barcode_Time1);

\$diff=strtotime(\$b3)-strtotime(\$b2);

\$diff1=date("H:i:s", \$diff);

plz solve this problem

• Well, since your time only has a specific clock time no day or months, you can explode the time and convert it into seconds. Like this:

PHP Code:
``` \$tme = explode(":", \$b2);\$secs = (\$tme[0] * 3600) + \$tme[1] * 60 + \$tme[2];  ```
Do the same for the second time then subtract them. What you will have is the time difference in seconds. You can do an if > 60 to convert into minutes, if > 3600 to convert to hours.

And also try to format your PHP code.

• If you just want the difference, use UNIX Time, which is just time(); in php. It outputs the time in seconds from the date when the UNIX 'clock' was started. You just have to take the difference between the two numbers. One day is 86400 seconds.

• DrDos, if you check the times he has provided...they do not have the day, month or year. So using time() will not really give him a time since the UNIX clock was started.

• Originally Posted by Redcoder
DrDos, if you check the times he has provided...they do not have the day, month or year. So using time() will not really give him a time since the UNIX clock was started.
Quite correct, but nothing really prevents him from adding it into the code somewhere, and it's a lot easier to deal with and compare.

•

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•