reschedule

Prev Next

Function Names

reschedule

Description

This function reschedules the date provided to a different date. At least 3 parameters are required: The date, and at least one pair of two rescheduling parameters. Additional pairs of rescheduling parameters can be added which is useful to make a big rescheduling first, e.g. next year, followed by a smaller rescheduling, e.g. the 2nd week in that year.

Note:As an exception, the parameters for this function are not case-senstitive.

Vectorization: This function supports vectorization in the 1st function parameter. Instead of providing a single value, you can provide a set or even a nested set which contain multiple values. The function will then process every value and its return value contains a corresponding set containing all results.

Following rescheduling parameter pairs are supported to reschedule dates whereas time information, if inside the date, remains unchanged:

rescheduling parameter 1 rescheduling parameter 2 description
next day (or days) Reschedules to next date (tomorrow)
previous day (or days) reschedules to previous date (yesterday)
1, 2, 3, ... day (or days) reschedules to next 1, 2, 3, ... days to the future
-1, -2, -3, ... day (or days) reschedules to next 1, 2, 3, ... days to the past
day number (1..31) rescheudles to nth day in the date (same year, same month)
begin week (or weeks) reschedules to begin of week (Monday) if date is not on a Monday
end week (or weeks) reschedules to end of week (Sudnay) if date is not on a Sunday
next week (or weeks) advances by 7 days
previous week (or weeks) moves 7 days backward
1, 2, 3, ... week (or weeks) advances 7, 14, 21, ... days
-1, -2, -3, ... week (or weeks) moves 7, 14, 21, ... days backward
week number (1..53) reschedules to nth week in year. Resulting date will always be Mondays.
begin month (or months) reschedules to begin (1st day) of month
end month (or months) reschedules to end (last day) of month
next month (or months) reschedules to next month, see 1
previous month (or months) reschedules to previous month, see 1
1, 2, 3, ... month (or months) reschedules to next 1, 2, 3, ... months, see 1
-1, -2, -3, ... month (or months) reschedules to previous 1, 2, 3, ... months, see 1
month number (1..12) reschedules to nth month, keeping the day unchanged where possible 1
begin quarter (or quarters) reschedules to begin of quarter (1. January, 1. April, 1. July, 1. October)
end quarter (or quarters) reschedules to end of quarter (31. January, 30. June, 30. September, 31. December)
next quarter (or quarters) reschedules to next quarter, see 1
previous quarter (or quarters) reschedules to previous quarter, see 1
1, 2, 3, ... quarter (or quarters) reschedules to next 1, 2, 3, ... quarters, see 1
-1, -2, -3, ... quarter (or quarters) reschedules to previous 1, 2, 3, ... quarters, see 1
quarter number (1..4) reschedules to 1st month of corresponding quarter, see 1
begin year (or years) reschedules to begin of year (1. January)
end year (or years) reschedules to end of year (31. December)
next year (or years) reschedules to same date on next year. For leapyears, see 1
previous year (or years) reschedules to same date on previous year. For leapyears, see 1
1, 2, 3, ... year (or years) reschedules to next 1, 2, 3, ... years. For leapyears, see 1
-1, -2, -3, ... year (or years) reschedules to previous 1, 2, 3, ... years. For leapyears, see 1
year 4-digit year, e.g. 2020 rescheudles to a specified year, see 1
this monday ... sunday reschedules to a specified day within the week (week is from Monday to Sunday)
next monday ... sunday reschedules to a later day. If the date is on the specified weekday, then it's next week.
previous monday ... sunday reschedules to an earlier day. If the date is on the specified weekday, then it's 1 week back.

1 If the day in the date is bigger then the number of months to be rescheudled to (e.g. 31. March to February), then the day will be adjusted to last day of the month accordingly.
Following rescheduling parameter pairs are supported to reschedule date and time combinations (00:00:00 is assumed as initial time if no time is provided):

rescheduling parameter 1 rescheduling parameter 2 description
begin day (or days) Same day, reschedules to 00:00:00
end day (or days) Same day, reschedules to 23:59:59
begin hour (or hours) Same day, reschedules to hh:00:00 (hh = current hour)
end hour (or hours) Same day, reschedules to hh:59:59 (hh = current hour)
next hour (or hours) Reschedules to next hour, see 2
previous hour (or hours) Reschedules to previous hour, see 2
1, 2, 3, ... hour (or hours) Reschedules to next 1, 2, 3, ... hours, see 2
-1, -2, -3, ... hour (or hours) Reschedules to previous 1, 2, 3, ... hours, see 2
hour number (0..23) Reschedules to a specified hour
begin minute (or minutes) Same day, reschedules to hh:mm:00 (hh:mm = current hour and minute)
end minute (or minutes) Same day, reschedules to hh:mm:59 (hh:mm = current hour and minute)
next minute (or minutes) Reschedules to next minute, see 2
previous minute (or minutes) Reschedules to previous minute, see 2
1, 2, 3, ... minute (or minutes) Reschedules to next 1, 2, 3, ... minutes, see 2
-1, -2, -3, ... minute (or minutes) Reschedules to previous 1, 2, 3, ... minutes, see 2
minute number (0..59) Reschedules to a specified minute
begin second (or seconds) No impact, value stays unchanged
end second (or seconds) No impact, value stays unchanged
next second (or seconds) Reschedules to next second, see 2
previous second (or seconds) Reschedules to previous second, see 2
1, 2, 3, ... second (or seconds) Reschedules to next 1, 2, 3, ... seconds, see 2
-1, -2, -3, ... second (or seconds) Reschedules to previous 1, 2, 3, ... seconds, see 2
second number (0..59) Reschedules to a specified second

Call as: function

Restrictions

Indirect parameter passing is disabled
Vectorization is allowed in the 1st function parameter

Parameter count

3, 5, 7, ...

Parameters

No.TypeDescription
1
input
date or string converted to date
set
Date

Date to reschedule. Or make use of vectorization to embed mulitple dates in a (nested) set and calculate all of them.

2, Opt 4,...
input
string
numeral
Rescheduling parameter 1

See table above

3, Opt 5,...
input
string
numeral
Rescheduling parameter 2

See table above

Return value

TypeDescription
date rescheduled date

Rescheduled date. Plain dates remain as plain dates regardless how they are rescheduled.

Examples

               echo( reschedule ( "2011-12-24", -1, days )); //  2011-12-23
               echo( reschedule ( "2012-01-31", 1, month )); //  2012-02-29
               echo( reschedule ( "2011-12-06", end, month )); // 2011-12-31
               echo( reschedule ( "2011-03-04", next, week)); //  2011-03-11
               echo( reschedule ( "2011-03-04", day, 5)); //  2011-03-05
               echo( reschedule ( "2012-12-31", next, week, end, week)); // 2013-01-13
               echo( reschedule ( "2011-03-04", week, 25)); //  2011-06-20
               echo( reschedule ("", 1, day)); //            Returns blank date
               echo( reschedule ( now, time, "15:30" )); //    Changes time to 15:30.
               echo( reschedule ( {now, "2011-03-04"} , time, "15:30" ));  // Vectorization

Output

2011-12-23
2012-02-29
2011-12-31
2011-03-11
2011-03-05
2013-01-13
2011-06-20

2024-10-19 15:30:00
{'2024-10-19 15:30:00','2011-03-04 15:30:00'}
Try it yourself: Open LIB_Function_reschedule.b4p in B4P_Examples.zip. Decompress before use.