Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-DBAAgentJobHistory adding an hour on to the enddate and duration #4345

Closed
NickGuy1 opened this issue Oct 25, 2018 · 7 comments
Closed

Get-DBAAgentJobHistory adding an hour on to the enddate and duration #4345

NickGuy1 opened this issue Oct 25, 2018 · 7 comments
Assignees

Comments

@NickGuy1
Copy link

NickGuy1 commented Oct 25, 2018

#issue
Issues seen with duration and enddate adding an extra hour on to some jobs
tested on dbatools verion 0.9.490

#reproduce
I've been able to reproduce this using the logic from Get-JobHistory
$DurationInSeconds = ($execution.RunDuration % 100) + [int]( ($execution.RunDuration % 10000 ) / 100 ) * 60 + [int]( ($execution.RunDuration % 1000000 ) / 10000 ) * 60 * 60

where runduration in this case is the equivalent of 1 hours 56 minutes 14 seconds

$runduration = 15614

The current function logic returns:
Enddate: 25 October 2018 03:02:15

$durationinseconds = ($runduration % 100) + [int]( ($runduration % 10000 ) / 100 ) * 60 + [int]( ($runduration % 1000000 ) / 10000 ) * 60 * 60
(get-date -date "2018-10-25 00:06:01.000").AddSeconds($durationinseconds)

using logic from Rob's post
https://sqldbawithabeard.com/2016/09/12/converting-sql-agent-job-duration-to-timespan-using-powershell/

[timespan]$durationinseconds2 = ($runduration).tostring().padleft(6,'0').insert(4,':').insert(2,':')
(get-date -date "2018-10-25 00:06:01.000").AddSeconds($durationinseconds2.TotalSeconds)

returns
25 October 2018 02:02:15

which is the expected result based on sql agent job history

@stale
Copy link

stale bot commented Jan 24, 2019

This issue has been automatically marked as stale because it has not had recent activity. If you would like this issue to remain open:

  • Verify that you can still reproduce the issue in the latest version of dbatools
  • Comment that the issue is still reproducible and include:
    • What version of dbatools you reproduced the issue on
    • What OS and version you reproduced the issue on
    • What steps you followed to reproduce the issue

@stale stale bot added the wontfix label Jan 24, 2019
@stale
Copy link

stale bot commented Feb 23, 2019

This issue has been automatically closed because it has not had activity in the last three months. If this issue is still valid, please add a comment

@stale stale bot closed this as completed Feb 23, 2019
@SQLGB
Copy link
Contributor

SQLGB commented Mar 4, 2019

I observed this issue today with build 0.9.777 on at least one server out of 100 that I queried, and was wondering why this bug report appears to be closed as stale / won't fix?

@wsmelton wsmelton reopened this Mar 4, 2019
@stale stale bot removed the wontfix label Mar 4, 2019
@SQLGB
Copy link
Contributor

SQLGB commented Mar 4, 2019

Thanks for re-opening. I re-checked my results; in a query of one job on each of 86 instances, 16 reported incorrect Duration and EndDate. But it's not always a one hour difference; sometimes it's a difference of just one minute.

@SQLGB
Copy link
Contributor

SQLGB commented Mar 5, 2019

As @NickGuy1 mentioned in his original bug report, the formula for $DurationInSeconds returns incorrect values in some cases. If the digit in the "tens" position of either seconds or minutes (possibly hours also) is a 5 and any other digits are greater than zero, an incorrect result is returned. Input of "50" seconds returns output of 50 seconds; input of 51 seconds returns output of 111 seconds (instead of 51). Input of 50 minutes returns 3000 seconds; input of 51 minutes returns 6660 seconds (instead of 3060).

SQLGB added a commit to SQLGB/dbatools that referenced this issue Mar 5, 2019
@SQLGB
Copy link
Contributor

SQLGB commented Mar 5, 2019

Submitted pull request.

#5157

@potatoqualitee
Copy link
Member

fantastic, thank you, @SQLGB!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants