A utility function in UserSpice that returns a date offset by a certain number of units, based on the input parameters.
Location
users/helpers/us_helpers.php
Parameters
#
Parameter
Data Type
Required
Description
1
$number
integer
Yes
A positive or negative integer representing the number of units by which to offset the date. The value must be an integer, but can be positive or negative.
2
$datestring =
string
Yes
A string representing the unit of time to be used for the offset. The value must be one of the following: day, week, month, or year. The string is not case-sensitive.
3
$unit =
string
No
A string representing the starting date for the offset. The string must be in a valid date format. If this parameter is not provided, the current date is used as the starting point for the offset.
4
$datestring = ""
Yes
undocumented
5
$unit = "days"
Yes
undocumented
Returns
Data Type
Description of Returned Data
string
Returns a string representing the offset date, in the format YYYY-MM-DD.
Further Documentation:
The offsetDate() function is a utility function in UserSpice that returns a date offset by a certain number of units, based on the input parameters.
Example Usage:
// Offset the current date by 3 days $newDate = offsetDate(3, 'day');
echo $newDate; // Outputs something like: "2023-04-20"
// Offset a specific date by 1 month $startDate = "2023-01-15"; $newDate = offsetDate(1, 'month', $startDate);
echo $newDate; // Outputs "2023-02-15"