Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# confusing time_difference invoice to calculate total_time

Posted on 2013-05-22
Medium Priority
169 Views
doing programming hours invoice
sometimes I know the start_time - end_time
and other times I just know the daily hours (for days where I work 1 hour, take a 2 hour break work 3 more hours, take a 5 hour break, work 1 more hour)

3 mysql columns
start_time datetime
end_time datetime
time_difference   (maybe I should use int and calculate seconds)

I am confused with time_difference (php form input textbox)
a user is entering time_difference (sometimes calculated from start_time-end_time, sometimes without start_time_endtime) in an input textbox which gets saved into mysql and then displayed in the input textbox again

hours minutes in this format:
h:i

6:05

want to convert
to seconds mysql format int (because it is difficult to say that I worked 1800439 seconds in one day)

and then back into
h:i

how to do the two conversions

note that the total_time is the sum of all the time_difference

is there a better way to do this
0
Question by:rgb192
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 6

Accepted Solution

mickey159 earned 2000 total points
ID: 39188592
``````function time_to_str(\$str){
\$c=explode(":",\$str);
\$int=\$c[0]*3600+\$c[1]*60;
return \$int;
}

function str_to_time(\$int){
\$hrs=floor(\$int/3600);
\$mins=(\$int-\$hrs*3600)/60;
\$str=\$hrs.":".(\$mins<10?"0".\$mins:\$mins);
return \$str;
}
``````

I hope this helps. :-)
0

Author Closing Comment

ID: 39191171
these two functions work great in textbox and mysql

thank you
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
###### Suggested Courses
Course of the Month7 days, 10 hours left to enroll