datediff not accurate.
Forum rules
When reporting a bug, please include the following information: your XYplorer version (e.g., v27.90.0047), your Windows version (e.g., Win 11), and your screen scaling percentage (e.g., 125%). We recommend adding your Windows version and screen scaling percentage to your profile or signature. This will make debugging much easier for us.
When reporting a bug, please include the following information: your XYplorer version (e.g., v27.90.0047), your Windows version (e.g., Win 11), and your screen scaling percentage (e.g., 125%). We recommend adding your Windows version and screen scaling percentage to your profile or signature. This will make debugging much easier for us.
Re: datediff not accurate.
Can you please use code tags for your code? Thank you 
Reporting a bug? Have a wish? Got a question? Use search - View roadmap - FAQs: Forum + XY site
Windows 7/10
Always using the latest stable two-decimal build
Windows 7/10
Always using the latest stable two-decimal build
Re: datediff not accurate.
Despite admin's helpful additions to math, I am still looking after a reliable method to convert seconds in hours and minutes. Took 4 different approaches and still stuck on this. Any help...?
14398 secs = 3h 59min 58sec
14398 secs = 3h 59min 58sec
Power-hungry user!!!
-
admin
- Site Admin
- Posts: 64838
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: datediff not accurate.
Try this for starters (not throroughly tested). Indeed integer division and modulo are applied:tiago wrote:Despite admin's helpful additions to math, I am still looking after a reliable method to convert seconds in hours and minutes. Took 4 different approaches and still stuck on this. Any help...?
14398 secs = 3h 59min 58sec
Code: Select all
// format duration given in seconds
$DAYS_PER_YEAR = 365.25;
$HOURS_PER_DAY = 24;
$MINS_PER_HOUR = 60;
$SECS_PER_MIN = 60;
$duration = "";
$Secs = 14398;
$Mins = $Secs \ $SECS_PER_MIN;
$Hours = $Mins \ $MINS_PER_HOUR;
$Days = $Hours \ $HOURS_PER_DAY;
$Years = $Days \ $DAYS_PER_YEAR;
If ($Years > 0) {
$duration = $Years . "y";
}
$Days = $Days % $DAYS_PER_YEAR;
If ($Days > 0) {
$duration = $duration . " " . $Days . "d";
}
$Hours = $Hours % $HOURS_PER_DAY;
If ($Hours > 0) {
$duration = $duration . " " . $Hours . "h";
}
$Mins = $Mins % $MINS_PER_HOUR;
If ($Mins > 0) {
$duration = $duration . " " . $Mins . "min";
}
$Secs = $Secs % $SECS_PER_MIN;
If ($Secs > 0) {
$duration = $duration . " " . $Secs . "sec";
}
echo $duration;FAQ | XY News RSS | XY X
Re: datediff not accurate.
It worked after a little upgrade, have to learn to keep an eye on your beta releases. Works like a charm, admin! Sorry for bothering even after all the implements you made, missed that "integer division" upgrade. THAT'S precision enough! 
Power-hungry user!!!
-
j_c_hallgren
- XY Blog Master
- Posts: 5826
- Joined: 02 Jan 2006 19:34
- Location: So. Chatham MA/Clearwater FL
- Contact:
Re: datediff not accurate.
Yes, we know that one must check at least daily for newest vers here!tiago wrote:It worked after a little upgrade, have to learn to keep an eye on your beta releases. Works like a charm, admin!
And yes, Don is 'admin' here but prefers his name to that title, I think.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
-
admin
- Site Admin
- Posts: 64838
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: datediff not accurate.
Here's an improved version (in the last version the return had a leading space character):
Code: Select all
// format duration given in seconds
$DAYS_PER_YEAR = 365.25;
$HOURS_PER_DAY = 24;
$MINS_PER_HOUR = 60;
$SECS_PER_MIN = 60;
$sep = " ";
$duration = "";
$Secs = 14398;
$Mins = $Secs \ $SECS_PER_MIN;
$Hours = $Mins \ $MINS_PER_HOUR;
$Days = $Hours \ $HOURS_PER_DAY;
$Years = $Days \ $DAYS_PER_YEAR;
If ($Years > 0) {
$duration = $duration . $sep . $Years . "y";
}
$Days = $Days % $DAYS_PER_YEAR;
If ($Days > 0) {
$duration = $duration . $sep . $Days . "d";
}
$Hours = $Hours % $HOURS_PER_DAY;
If ($Hours > 0) {
$duration = $duration . $sep . $Hours . "h";
}
$Mins = $Mins % $MINS_PER_HOUR;
If ($Mins > 0) {
$duration = $duration . $sep . $Mins . "min";
}
$Secs = $Secs % $SECS_PER_MIN;
If ($Secs > 0) {
$duration = $duration . $sep . $Secs . "sec";
}
// cut initial sep
$duration = substr($duration, strlen($sep));
echo $duration;FAQ | XY News RSS | XY X
Re: datediff not accurate.
Thank you, I easily integrated your script into those mine which were lacking such as my only functional code was ruined when floating appear.
Power-hungry user!!!
XYplorer Beta Club