datediff not accurate.
Forum rules
READ THIS AND DO IT!!!
Please include the following information:
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).
We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.
When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".
READ THIS AND DO IT!!!
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).
-
zer0
- Posts: 2676
- Joined: 19 Jan 2009 20:11
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
-
admin
- Site Admin
- Posts: 66203
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
-
tiago
- Posts: 589
- Joined: 14 Feb 2011 21:41
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: 66203
- 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
-
tiago
- Posts: 589
- Joined: 14 Feb 2011 21:41
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: 66203
- 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
-
tiago
- Posts: 589
- Joined: 14 Feb 2011 21:41
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