Currently, there is no way of using relative dates to search through the API (for example: last month or 30 days ago).
Solution
Calculate the date/time using the current date and representing it in an accepted format for the findObjects command.
Examples
Create a script with findObjects in it, using the following filter:
{
propertyName => "start",
operator => "lessOrEqual",
operand1 => computeDaysAgoTimeStamp(30)
}
# where computeDaysAgoTimestamp is a sub:
# ----------------------------------------------------------------------
# computeDaysAgoTimeStamp
# Computes current-time minus $daysAgo in GMT time, for passing into
# a date filter (e.g. startTime <= 3 days ago).
#
# Arguments:
# daysAgo - number of days ago.
# ----------------------------------------------------------------------
sub computeDaysAgoTimeStamp($) {
my ($daysAgo) = @_;
# Get current time.
my $curTime = time();
# Subtract $daysAgo days.
$curTime -= 3600*24*$daysAgo;
# Convert this time to y-m-d format and return it.
my ($sec, $min, $hour, $mday, $mon, $year) = gmtime($curTime);
my $dateStr = sprintf("%4d-%02d-%02dT%02d:%02d:%02d.000Z", 1900+$year,
$mon+1, $mday, $hour, $min, $sec);
return $dateStr;
}
This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.