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.
datediff not accurate.
datediff should calculate hours intervals based on minutes actually involved and not the simple 14:00:01 - 13:58:32 = 1 hour! Same goes for minutes being calculated on actual number of seconds and rounding down for each passed 60 secs.
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.
Well, depends on your purpose. I formed the functionality after the widely used VBA DateDiff.
FAQ | XY News RSS | XY X
Re: datediff not accurate.
Well, the purpose is to have an accurate datediff method to rely on.
Tried some scripting on this but got stuck at a point, had come ideas, made notes and report back if I find a reasonable solution.
Tried some scripting on this but got stuck at a point, had come ideas, made notes and report back if I find a reasonable solution.
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.
You can simply increase the resolution by asking for the difference in seconds, and then calculate from there manually.tiago wrote:Well, the purpose is to have an accurate datediff method to rely on.![]()
Tried some scripting on this but got stuck at a point, had come ideas, made notes and report back if I find a reasonable solution.
FAQ | XY News RSS | XY X
Re: datediff not accurate.
Yeah, that was the first idea.
Then I obviously stumble upon the inaccuracy itself again and using format/formatbytes didn't helped much as far as I can remember. I'll probably revise my attempts again and post any solution I may find, in hopes that someone bothers for such a thing.
Then I obviously stumble upon the inaccuracy itself again and using format/formatbytes didn't helped much as far as I can remember. I'll probably revise my attempts again and post any solution I may find, in hopes that someone bothers for such a thing.
Power-hungry user!!!
Re: datediff not accurate.
This has turning into an interesting problem.
Yes, it seems to be a "widely used" method out there or two, the most dangerous being: almost all online converters I found to debug my calculations just do the whole hours or minutes part, so they're not doing a reliable calculation too.
The problem I'm stuck in: XY does not rounds down or up decimal numbers. Does it?
So in case your diff is 3601 seconds, prepare to have a little annoyance.
Yes, it seems to be a "widely used" method out there or two, the most dangerous being: almost all online converters I found to debug my calculations just do the whole hours or minutes part, so they're not doing a reliable calculation too.
The problem I'm stuck in: XY does not rounds down or up decimal numbers. Does it?
So in case your diff is 3601 seconds, prepare to have a little annoyance.
Code: Select all
// $reportModifiedDate2 = <date hh:nn:ss yyyy/mm/dd>; // this is the real thing, replaced for debug reasons
$reportModifiedDate1 = "13:58:58"; //
//time of script execution, emulated by wait()
//in case, YOUR SCRIPT GOES HERE.
// focus pi; //debug purposes only - remove for real usage.
// status "Plz wait 1 min - timer on, $reportModifiedDate1"; //debug purposes only - remove for real usage.
// wait(62000); //debug purposes only - remove for real usage.
// focus pi; //debug purposes only - remove for real usage.
//in case, YOUR SCRIPT ENDS HERE.
// $reportModifiedDate2 = <date hh:nn:ss yyyy/mm/dd>; // this is the real thing, replaced for debug reasons
$reportModifiedDate2 = "16:32:01"; // 15:02:01 , test hr // 14:02:01 , test min // 13:59:41 , test sec
$differenceOfDates = datediff($reportModifiedDate1, $reportModifiedDate2, s);
// $differenceOfDates = 3601; // debug purposes
IF ($differenceOfDates <= 59)
{
echo "$reportModifiedDate1 - starting date;<crlf>$reportModifiedDate2 - ending date;<crlf><crlf>$differenceOfDates - difference in seconds.";
}
ELSEIF ($differenceOfDates <= 3599)
{
$minMIN1 = $differenceOfDates / 60;
$minMIN2a = gettoken($minMIN1, 1, ".");
$minMIN2b = gettoken($minMIN1, 2, ".");
$minMIN3 = "0.$minMIN2b" * 60;
$minMIN4 = format($minMIN2a, "00");
$minMIN5 = format($minMIN3, "00");
$minR = "$minMIN4" . ":" . "$minMIN5";
echo "$reportModifiedDate1 - starting date;<crlf>$reportModifiedDate2 - ending date;<crlf><crlf>$differenceOfDates - difference in seconds;<crlf>$minR - difference in minutes.";
}
ELSEIF ($differenceOfDates >= 3600)
{
$minMINa = $differenceOfDates / 3600;
$minMINba = gettoken($minMINa, 1, ".");
$minMINbb = gettoken($minMINa, 2, ".");
$minMINc = "0.$minMINbb" * 3600;
$minMINd = format($minMINba, "00");
$minMINe = format($minMINc, "00");
$minMIN6 = $minMINe / 60;
$minMIN7a = gettoken($minMIN6, 1, ".");
$minMIN7b = gettoken($minMIN6, 2, ".");
$minMIN8 = "0.$minMIN7b" * 60;
$minMIN9 = format($minMIN7a, "00");
$minMINx = format($minMIN8, "00");
$minRH = "$minMINba" . ":" . "$minMIN9";
$minMIN1 = $differenceOfDates / 60;
$minMIN2a = gettoken($minMIN1, 1, ".");
$minMIN2b = gettoken($minMIN1, 2, ".");
$minMIN3 = "0.$minMIN2b" * 60;
$minMIN4 = format($minMIN2a, "00");
$minMIN5 = format($minMIN3, "00");
$minR = "$minMIN4" . ":" . "$minMIN5";
echo "$reportModifiedDate1 - starting date;<crlf>$reportModifiedDate2 - ending date;<crlf><crlf>$differenceOfDates - difference in seconds;<crlf>$minR - difference in minutes;<crlf>$minRH - difference in hours.";
}
status "done.";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.
Hmm, these are a lot of lines. What are you trying to achieve? Can you give an example?
FAQ | XY News RSS | XY X
Re: datediff not accurate.
I need to report among other stuff how much time XY toke to perform a job. Accurately, since currently I'm working for a non-profit NGO.
If I had a way to have gettoken being able to get tokens without separators, I guess I can easily solve the rounding up-or-down issue.
echo gettoken("Donald Duck", 4, ""); // returns "a"
echo gettoken("a,b,c,d,e", 4, ""); // returns ","
echo gettoken("a,b,c,d,e", 3, ""); // returns "b"
If I had a way to have gettoken being able to get tokens without separators, I guess I can easily solve the rounding up-or-down issue.
echo gettoken("Donald Duck", 4, ""); // returns "a"
echo gettoken("a,b,c,d,e", 4, ""); // returns ","
echo gettoken("a,b,c,d,e", 3, ""); // returns "b"
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.
A non-profit NGO needs to know how much time XY toke to perform a job? Anyway, seconds should be accurate enough, so where's the problem? Or do you want milliseconds?tiago wrote:I need to report among other stuff how much time XY toke to perform a job. Accurately, since currently I'm working for a non-profit NGO.
If I had a way to have gettoken being able to get tokens without separators, I guess I can easily solve the rounding up-or-down issue.
echo gettoken("Donald Duck", 4, ""); // returns "a"
echo gettoken("a,b,c,d,e", 4, ""); // returns ","
echo gettoken("a,b,c,d,e", 3, ""); // returns "b"
FAQ | XY News RSS | XY X
Re: datediff not accurate.
No, on the opposite: sometimes an operation takes HOURS to run.
And yes, I agree that seconds should suffice. I'm just bothered by delivering them "13601 seconds" as an output.
Precision is everything.
And yes, I agree that seconds should suffice. I'm just bothered by delivering them "13601 seconds" as an output.
Precision is everything.
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.
What is unprecise about "13601 seconds"?tiago wrote:No, on the opposite: sometimes an operation takes HOURS to run.
And yes, I agree that seconds should suffice. I'm just bothered by delivering them "13601 seconds" as an output.
Precision is everything.
FAQ | XY News RSS | XY X
Re: datediff not accurate.
The problem with precision is: your (VBA) datediff method says that 14:00:01 - 13:58:32 = 1 hour.
Correct: 89 secs or 01min 29sec.
13601 secs. Cool. Human friendliness: 226min 41 sec or 03h 46 min.
I think that math on XY could benefit If only there would be a way to round up or down decimals like in 2.33333333333333 turning into 2.33 or 2.3 or 2.4 (2.53333333333333) as per user choice.
Correct: 89 secs or 01min 29sec.
13601 secs. Cool. Human friendliness: 226min 41 sec or 03h 46 min.
I think that math on XY could benefit If only there would be a way to round up or down decimals like in 2.33333333333333 turning into 2.33 or 2.3 or 2.4 (2.53333333333333) as per user choice.
Power-hungry user!!!
Re: datediff not accurate.
Two beta on a single day and one containing a suggestion o'mine?
wow, thank you, Admin... Downloaded the version and will check it later so I can solve that little glitch on my script.
wow, thank you, Admin... Downloaded the version and will check it later so I can solve that little glitch on my script.
Power-hungry user!!!
Re: datediff not accurate.
Any idea on how do I translate the following PHP code into XYplorer script?
$seconds = 631;
$hours = floor($seconds / 3600);
$seconds -= $hours * 3600;
$minutes = floor($seconds / 60);
$seconds -= $minutes * 60;
echo "$hours : $minutes : $seconds";
$seconds = 631;
$hours = floor($seconds / 3600);
$seconds -= $hours * 3600;
$minutes = floor($seconds / 60);
$seconds -= $minutes * 60;
echo "$hours : $minutes : $seconds";
Power-hungry user!!!
XYplorer Beta Club