• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

ASH get date 7 days agao


In my bash scripts I can do:

DAY7=`date -I -d "7 days ago"`

When doing this in ash on my synology diskstation I get:

date: invalid date '7 days ago'

Is there any other way to do this that would work on ash?
  • 2
  • 2
1 Solution
pucko73Author Commented:
date -- help shows:

-d,--date TIME  Display TIME, not 'now'
I think it's not the shell, it's that your "date" command on your diskstation doesn't have the GNU extensiosn such as "7 days ago".

if you can use Perl, how about:
perl -MPOSIX -e 'print POSIX:strftime("%Y-%m-%d\n", localtime(time-(7*24*60*60)))'

Open in new window

(with the caveat that this doesn't necessarily cope in the week that daylight savings starts and stops, if it is called just before or after midnight)
Joseph GanSystem AdminCommented:
ash is very limited, it doesn't support additional functionality as bash does.
pucko73Author Commented:
[admin@DiskStation admin]$ perl -MPOSIX -e 'print POSIX:strftime("%Y-%m-%d\n", l
syntax error at -e line 1, near "POSIX:"
Execution of -e aborted due to compilation errors.
[admin@DiskStation admin]$
Ah, that's what comes of trying to write and test the code on one machine, and copy it to another!

There should be two colons in POSIX::strftime, so the whole line is:
$ perl -MPOSIX -e 'print POSIX::strftime("%Y-%m-%d\n", localtime(time-(7*24*60*60)))'
$ date
Mon Dec 16 22:20:18 GMT 2013

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now