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

2019-09-07 07:22发布

问题:

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.

回答1:

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


回答2:

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 ?