show yesterday by date command

Any questions about the Command Line Interface can be placed here!
Forum rules
Please note the disclaimer before modifying your Synology Product.

show yesterday by date command

Postby hankycheng » Fri May 04, 2012 5:38 am

Hi all

I want to show yesterday & before 5 days ago on screen
How to do that? Tks all!

It can be show date format like this
Code: Select all
NAS> date +%Y-%m-%d
2012-05-03


if I want to show yesterday day but fail

Code: Select all
NAS> date +%Y-%m-%d --date "yesterday"
date: invalid date 'yesterday'
hankycheng
I'm New!
I'm New!
 
Posts: 1
Joined: Fri May 04, 2012 5:33 am

Re: show yesterday by date command

Postby maxxfi » Fri May 04, 2012 9:37 am

Probably it cannot be done. I cannot check right now, but I guess 'date' command is implemented by the multi-binary busybox, which doesn't provide all the fanciest options.
Perhaps, if there is a date package in IPKG/optware, that one would likely support such a syntax.
DS-411 (DSM 4.2-3202) w/ 2x WD10EFRX + 1x HD154UI
DS-106j (DSM 3.0-1357), PATA-to-SATA adapter, 2.5" HM250HI
User avatar
maxxfi
Architect
Architect
 
Posts: 4317
Joined: Sun Dec 27, 2009 12:13 pm
Location: Espoo, Finland

Re: show yesterday by date command

Postby CoolRaoul » Sat May 05, 2012 9:54 am

hankycheng wrote:Hi all
if I want to show yesterday day but fail

Code: Select all
NAS> date +%Y-%m-%d --date "yesterday"
date: invalid date 'yesterday'

Strangely, even if DSM built-in "date" command in-line documentation show that "-d|--date" command arguments are supported (try "/bin/date --help") it doesn't seem to work as documented

If you've configured ipkg/optware you can install "corutils" package, whose "date" command fully supports "--date" with all GNU bells and whistles

***EDIT***
found a workaround removing the requirement to use any optware package:
http://lists.busybox.net/pipermail/busy ... 68752.html

this will do the trick using built-in "date":
Code: Select all
/bin/date -D "%s" -d $(( $(/bin/date +%s ) - 86400 )) +%Y-%m-%d
CR
CoolRaoul
Sharp
Sharp
 
Posts: 162
Joined: Tue May 18, 2010 7:08 pm


Return to Command Line Interface

Who is online

Users browsing this forum: Google [Bot] and 3 guests