|
|
|
<?
function m2h($mins) {
if ($mins < 0) {
$min = Abs($mins);
} else {
$min = $mins;
}
$H = Floor($min / 60);
$M = ($min - ($H * 60)) / 100;
$hours = $H + $M;
if ($mins < 0) {
$hours = $hours * (-1);
}
$expl = explode(".", $hours);
$H = $expl[0];
if (empty($expl[1])) {
$expl[1] = 00;
}
$M = $expl[1];
if (strlen($M) < 2) {
$M = $M . 0;
}
$hours = $H . "." . $M;
return $hours;
}
?>
Example :
<?
Echo m2h(120);
?>
Will output 2.00
<?
Echo m2h(119);
?>
Will output 1.59
|
|
| 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 | |
| | | | matthew waygood wrote : 925
This would be much easier.
function m2h($mins)
{
$min=abs($mins);
$H = floor($min/60);
$M = ($min - ($H*60) ) / 100;
$hours = $H+$M;
if($mins<0)
{
$hours=-$hours;
}
return number_format($hours,2);
}
?>
| | | | Fred Schenk wrote : 934
IMHO the "abs" isn`t necessary. And if PHP has a modulo-function the whole function can be rewritten as:
hours = floor(minutes/60) + (minutes mod 60)/100
Gtx,
Fred
| | | | matthew waygood wrote :938
abs IS necessary as :-
floor(2.5) = 2
floor(-2.5) = 3
I tested if ABS was necessay BEFORE adding the comment, I suggest you do the same in future.
| |
|
|
|