Solved

confusing time_difference invoice to calculate total_time

Posted on 2013-05-22
2
155 Views
Last Modified: 2013-05-23
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
Comment
Question by:rgb192
2 Comments
 
LVL 6

Accepted Solution

by:
mickey159 earned 500 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;
}

Open in new window


This should solve your problem.
I hope this helps. :-)
0
 

Author Closing Comment

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

thank you
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now