有没有办法编写一个公式,将 n 天数添加到返回新日期的现有日期,但不包括周末?
答案 0 :(得分:0)
你的意思是“考虑到一天,添加任意天数,但确保新的日期不会在周末出现?”
如果是这样,您选择的语言应该随时为您提供一个功能,以确定一周中的哪一天。通常,0表示星期日,6表示星期六。
这是一些伪代码:
newDate = myDate + random(1, n); // n is whatever largest integer you want.
//random(1, n) would be give me any number between 1 and n inclusive.
while ((newDate.dayOfWeek == 0) || (newDate.dayOfWeek == 6))
newDate = myDate + random(1, n);
// keep on generating a new date until it's not Sunday or Saturday.
// At this point, newDate is guaranteed not to fall on a weekend.