How to subtract or add days or months to a date on

2019-09-07 07:04发布

Linux date has the -d feature which is missing in Solaris. So how can I go about subtracting or adding days or months to a date on Solaris.

2条回答
Rolldiameter
2楼-- · 2019-09-07 07:14

What you need is GNU date for Solaris. (Linux uses GNU tools)

If you are using a recent version of Solaris (no my friend, Solaris 10 can no longer be considered a recent version of Solaris) then it is installed by default. Just use gdate command instead of date command.

This reply has more answers for you. Just follow the links in that reply for what to do on Solaris 10. You sysadmin may already have done this for you. Before you proceed: Have you checked if gdate is available on your system ?

查看更多
老娘就宠你
3楼-- · 2019-09-07 07:30

you still can do this with perl or python oneliners, e.g., substract one day from current date:

$ date
Thu May 14 15:31:49 MEST 2015
$ python -c "from datetime import datetime, timedelta; print (datetime.now() - timedelta(1)).strftime('%c');"
Wed May 13 15:31:58 2015
查看更多
登录 后发表回答