Questions will get answered quicker if you provide some code and a dataset to go with it.
I've worked out how to do this for a particular week. You can generalize this for any date range by generating the weekday dates and times that you want to exclude.
(*make a dataset for the example*)
datesample = RandomInteger[{AbsoluteTime[{2015, 03, 22}],
AbsoluteTime[{2015, 03, 28}]}, 1000];
data = Transpose@{DateList /@ datesample , RandomReal[{20 10^3, 90 10^3}, 1000]};
(*Create the interval over which items should be deleted. Make a function
that takes the start and end dates and returns the union of the intervals.*)
delInterval = Interval[{AbsoluteTime[{2015, 03, 23, 22, 0}], AbsoluteTime[{2015, 03, 23, 22, 59}]},
{AbsoluteTime[{2015, 03, 27, 8, 0}], AbsoluteTime[{2015, 03, 27, 9, 59}]}];
(*Delete items inside of the interval.*)
DeleteCases[x_ /; IntervalMemberQ[ delInterval, AbsoluteTime[x[[1]]]]]@data
Items with date times that fall in the two specified will match and be deleted.
Update with Interval
creation function
You can generate a interval exclusion Interval
by using function that takes start and end dates along with the days and time periods.
startDate = {2014, 1, 8}; endDate = {2015, 3, 23};
timeSpans = {{Monday, {{22, 0}, {22, 59,59}}}, {Friday, {{8, 0}, {9, 59, 59}}}};
This function takes information, finds the first day of the week for each timeSpans
set, and generates all the weekday time intervals between the start and end date.
dateTimeInterval[start_, end_, day_, timeSpan_] :=
Module[
{first = Piecewise[{{start, DayName[start] == day}, {DayPlus[start, 1, day], True}}]},
datetimes = (
Function[{time},
DateObject[DatePlus[first, {#, "Week"}], TimeObject[time]]] /@ timeSpan) & /@
Range[QuantityMagnitude@DateDifference[first, end, "Week"]];
Interval[Sequence @@ Map[AbsoluteTime, datetimes, {2}]]
]
So now, starting from the top, we can generate a much larger test dataset and apply the new method to it.
(*Make a dataset for the example*)
datesample = RandomInteger[{AbsoluteTime[startDate], AbsoluteTime[endDate]}, 10000];
data = Transpose@{DateList /@ datesample , RandomReal[{20 10^3, 90 10^3}, 10000]};
(*Create the interval over which items should be deleted.*)
delInterval =
IntervalUnion[Sequence @@ (dateTimeInterval[startDate, endDate, Sequence @@ #] & /@ timeSpans)];
(*Delete items inside of the interval.*)
cleanedData = DeleteCases[x_ /; IntervalMemberQ[delInterval, AbsoluteTime[x[[1]]]]]@data
You can also grab the location of the items that will be deleted. Which is useful if you want to do something with them.
Position[data, item_ /; IntervalMemberQ[delInterval, AbsoluteTime[item[[1]]]], {1}]
This does give an odd error but it completes ok. Anyone have an idea why this Position
errors please make a note in the comments.
Hope this helps. - Don't forget to accept an answer by clicking the checkmark next to it in the left margin.