|
|
|
<?
function h2m($hours) {
$t = explode(".", $hours);
$h = $t[0];
if (isset($t[1])) {
$m = $t[1];
} else {
$m = "00";
}
return ($h * 60) + $m;
}
// I have to add together hundreds of shift times (for a timesheet
// application), shift times are given in hours and minutes - the solution
// is to convert each shift to minutes (1.45 -> 105, 0.45-> 45), add them
// together (105+45 -> 150), and used the minutes to hours function to
// return the total hours and minutes (150 -> 2.30).
// More Exmaples :
// 1.5 hours is taken to mean 1.05, 1 hour and 5 minutes.
// 0.65 hours means 65 minutes
?> |
|
| A Timing Class Categories : PHP, PHP Classes, Date Time | | | Finding the day of the week for a specific date.
Categories : PHP, Databases, MySQL, Date Time | | | A wrapper function to format dates coming from a databases with the
same syntax as PHP's date() function. Categories : Date Time, Databases, PHP | | | pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes | | | A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function. Categories : PHP, PHP Classes, Calendar, Date Time | | | PHP Round Clock - Must have Gif support to use this. Categories : PHP, Date Time, Graphics | | | A simple and fast calendar combining PHP and tables. Use this as a base for applications in which a calendar is needed. Categories : Date Time, PHP, Complete Programs, Calendar | | | Open and Close your website in fixed times . Categories : PHP, PHP Classes, Cron, Date Time | | | mysql date/time converters Categories : PHP, MySQL, Databases, Date Time | | | Creates three SELECT form fields: Month, Day, and Year. You give it a string which will be used to make the name for the three fields, and a number of seconds to use as the default date. If you give it blank for this value, the current date is used. Categories : HTML and PHP, PHP, Date Time | | | If you want to create select buttons featuring current date this example will show you how... Categories : Date Time, HTML and PHP, PHP | | | Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example. Categories : PHP, Date Time, PHP Classes, Calendar | | | calculus of the eastersunday Categories : BC math, PHP, Date Time, Databases | | | Functions used to define a schedule of holidays. Can define non-fixed holidays (eg. 3rd sunday of June). Categories : Calendar, Date Time, PHP | | | Monthly and Daily Upcoming Events calendar. Categories : Date Time, PostgreSQL, PHP, Calendar, Databases | |
| | | | Justin French wrote :937
Seems a little counter-intuitive to me.
1.5 should represent 1.5 hours, NOT 1 hour and 5 minutes... even 1.05 would make more sense. Better, still, why not accept multiple formats:
`44` = 44 hours
`3.75` = 3 and 3/4 hours
`8:24` = 8 hours, 24 minutes
Then wrap it all in one function:
<?
function h2m($input)
{
if(ereg(`:`,$input))
{
// we`re working in h:m mode
list($h,$m) = explode(`:`,$input);
$mins = ($h * 60) + $m;
}
else
{
// we`ve been passed a decimal or whole number
$mins = $input * 60;
$mins = round($mins);
}
return $mins;
}
// Examples:
echo "3.75 hours is ".h2m(`3.75`)." minutes <br />\n";
echo "3:27 hours is ".h2m(`3:27`)." minutes <br />\n";
echo "44 hours is ".h2m(`44`)." minutes <br />\n";
?>
Obviously some more format checking could be done, but you get the idea.
| |
|
|
|