How to remove job history for a TIME PERIOD in SQL Server I am trying to purge / delete history for all jobs that ran for a week. How could I achieve this?
Please note that I've read this article that talks about deleting history for a SPECIFIC JOB (I have 200 jobs and can't use that).
Someone tried to manually delete it from table but apparently that can have bad consequences.
I also wanted to add that Purging UP TO A DAY is NOT acceptable. I need to delete a range (say Jan/04 - Jan/15). All days up to Jan 4 and after Jan 15 must remain.
You could just delete from the sysjobhistory table - as this is essentially what sp_purge_jobhistory does under the covers anyway:

DELETE msdb.dbo.sysjobhistory
 WHERE run_date BETWEEN '2019-01-04' AND '2019-01-15';


Though, as you have pointed out - it isn't officially supported and could have unintended consequences. With that in mind, there is an official supported way to do it using the JobServer class of SQL Server Management Objects:

The below is in C# because that is just what I prefer, but the documentation also has examples of doing the same in PowerShell:

// connect to the local instance
Server server = new Server();

// get the SQL Server Agent associated with the local instance
JobServer jobServer = server.JobServer;

// create a new job filter based on the criteria needed
JobHistoryFilter jobHistoryFilter = new JobHistoryFilter()
{
    StartDate = new DateTime(2019, 1, 4, 0, 0, 0),
    EndDate = new DateTime(2019, 1, 15, 23, 59, 59)
};

// now purge all data returned by the filter
jobServer.PurgeJobHistory(jobHistoryFilter);


And that's it! You could also condense it all into one call chain:

new Server().JobServer.PurgeJobHistory(new JobHistoryFilter()
{
    StartDate = new DateTime(2019, 1, 4, 0, 0, 0),
    EndDate = new DateTime(2019, 1, 15, 23, 59, 59)
});


I haven't put any error handling's in here but you should note that it could fail if you do not have permission to connect to the SQL Server, the SQL Server Agent, or if you do not have permission to query/modify msdb.

Here are some more useful links (and they also have PowerShell examples on them as well):

JobServer.PurgeJobHistory

JobHistoryFilter

Administrative Tasks in SMO

JobServer