amfmc Posted October 1, 2020 Share Posted October 1, 2020 Hello, I'm rather new to AutoIT but I'm using some code that uses the _datediff function and I was curious if it's possible to not have it round the difference. I've done as much research as I could to possibly find an answer about this but I can't seem to find one so I figured I would ask. Thanks Link to comment Share on other sites More sharing options...
TheXman Posted October 1, 2020 Share Posted October 1, 2020 (edited) 9 minutes ago, amfmc said: I was curious if it's possible to not have it round the difference What do you mean? You want it to not round the difference to what, the nearest minute, hour, day, week, month? Please provide a better explanation of what you're trying to do. It would also probably help if you posted the script or a good example of what you are working with and the expected result. Edited October 1, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
amfmc Posted October 1, 2020 Author Share Posted October 1, 2020 6 minutes ago, TheXman said: What do you mean? Round the difference to what, the nearest minute, hour, day, week, month? Please provide a better explanation of what you're trying to do. It would also probably help if you posted the script or a good example of what you are working with. Sorry, I'm doing a _datediff between two dates to figure out how many hours are in between that date and time. ; Calculates the hours between when the task was created and then worked. Local $iDateCalc = _DateDiff('h', $createdDate, $workedDate) After it does this different it comes out to be a rounded number and I don't want that. If "23.2345111" hours passed I want to see that not just "23" Link to comment Share on other sites More sharing options...
amfmc Posted October 1, 2020 Author Share Posted October 1, 2020 1 minute ago, amfmc said: different difference* not different Link to comment Share on other sites More sharing options...
TheXman Posted October 1, 2020 Share Posted October 1, 2020 (edited) Why not calculate the difference in minutes and then divide by 60? #include <Date.au3> example() Func example() Local $iDiffMins = _DateDiff("n", "2020/10/01 00:00:00", _NowCalc()) ConsoleWrite('Diff in Mins = ' & $iDiffMins & @CRLF) ConsoleWrite('Diff in Hours = ' & $iDiffMins / 60 & @CRLF) EndFunc Output: Diff in Mins = 785 Diff in hours = 13.0833333333333 Edited October 1, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
amfmc Posted October 1, 2020 Author Share Posted October 1, 2020 7 minutes ago, TheXman said: Why not calculate the difference in minutes and then divide by 60? #include <Date.au3> example() Func example() Local $iDiffMins = _DateDiff("n", "2020/10/01 00:00:00", _NowCalc()) Local $fDiffHours = $iDiffMins / 60 ConsoleWrite('Diff in Mins = ' & $iDiffMins & @CRLF) ConsoleWrite('Diff in hours = ' & $fDiffHours & @CRLF) EndFunc Output: Diff in Mins = 785 Diff in hours = 13.0833333333333 That's because it never occurred to me. It seems like that will work for me. I will do some testing with it. Thanks! Link to comment Share on other sites More sharing options...
TheXman Posted October 1, 2020 Share Posted October 1, 2020 (edited) You're welcome! If you want even more precision, then you can calculate the diff in secs and divide secs by 3600 to get hours. #include <Date.au3> example() Func example() Local $iDiffSecs = _DateDiff("s", "2020/10/01 00:00:00", _NowCalc()) ConsoleWrite('Diff in Secs = ' & $iDiffSecs & @CRLF) ConsoleWrite('Diff in Mins = ' & $iDiffSecs / 60 & @CRLF) ConsoleWrite('Diff in Hours = ' & $iDiffSecs / 3600 & @CRLF) EndFunc Console: Diff in Secs = 48288 Diff in Mins = 804.8 Diff in Hours = 13.4133333333333 Edited October 1, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now