简体   繁体   English

如何找到过去日期以后n天的日期?

[英]How to find date n days in the future from past date?

I want to find a date that is 57 –working– days after an arbitrary date using date or bash . 我想找到一个使用datebash在任意日期之后的57个工作日的日期。 For instance, 例如,

  1. today is august 21st, 今天是8月21日,
  2. reference date is july 15th, 参考日期是7月15日,
  3. what days will be 57 working days after july 15th? 7月15日之后的57个工作日是哪几天?

This should work to just get all days 这应该工作整天

date -d '7/15/14 +57 days'

To get number of work days (M..F) you can do something lazy like this 要获得工作日数(M..F),您可以像这样偷懒

#!/bin/bash
days=0
for ((i=1;i>0;i++)) do
  future=$(date -d "7/15/14 +$i days" '+%w')
  ((future!=0 && future!=6)) && ((days++))  # ignore sunday (0) and saturday (6)
  ((days==57)) && date -d "7/15/14 +$i days" && break
done

eg 例如

> ./abovescript
> Thu Oct  2 00:00:00 CDT 2014

Weird solution: 奇怪的解决方案:

day=21
mon=8
year=2014
days=4

curl -s "http://www.timeanddate.com/scripts/dateserver.php?mode=addweekdays&d1=$day&m1=$mon&y1=$year&type=add&ad=$days&atyp=0&ach=3" | sed -n 's|.*<h2>Result: \(.*\)</h2>.*|\1|p'

prints 版画

Wednesday, August 27, 2014

the date after 4 working days from 2014.08.21 从2014.08.21起4个工作日后的日期

for the 为了

day=15
mon=7
year=2014
days=57

prints 版画

Friday, October 3, 2014

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM