This is a discussion on OT: util for relative date? within the Slackware Linux Support forums, part of the Unix Operating Systems category; --> i'm looking for a util which, given an integer argument N, can print the date of the day N ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| i'm looking for a util which, given an integer argument N, can print the date of the day N days ago. example: $ day 2008/05/11 $ day -1 2008/05/10 $ day -12 2008/04/30 I can't figure how to get date(1) '--date=...' to do this for me. (well actually I can but it is simply too ugly for words :*) Does someone want to smack me with a Clue ? I suppose I should just do it in C and be done, but the idea seems so elementary that someone surely must have this already ? Thanks in advance for any comments, -- William Hunt, Portland Oregon USA |
| |||
| On Sun, 11 May 2008 11:30:51 -0700, William Hunt wrote: > i'm looking for a util which, given an integer argument N, can print the > date of the day N days ago. example: > $ day > 2008/05/11 > $ day -1 > 2008/05/10 > $ day -12 > 2008/04/30 > > I can't figure how to get date(1) '--date=...' to do this for me. (well > actually I can but it is simply too ugly for words :*) Does someone want > to smack me with a Clue ? I suppose I should just do it in C and be > done, but the idea seems so elementary that someone surely must have > this already ? > > Thanks in advance for any comments, You didn't say your reasons why you wouldn't use the 'fuzzy' date like: $ date --date "yesterday" Sat May 10 20:43:46 CEST 2008 $ date --date "now" Sun May 11 20:43:55 CEST 2008 $ date --date "2 days ago" Fri May 9 20:44:06 CEST 2008 $ date --date "next week" Sun May 18 20:44:20 CEST 2008 |
| |||
| William Hunt <wjh@prv8.net> typed on 2008-05-11: > > i'm looking for a util which, given an integer argument N, > can print the date of the day N days ago. > example: > $ day > 2008/05/11 > $ day -1 > 2008/05/10 > $ day -12 > 2008/04/30 #v+ #!/bin/bash date -d "${1} days" +%Y/%m/%d #v- Regards, -- Bartosz Oudekerk I think a better name for PAM might be SCAM, for Swiss Cheese Authentication Modules, and have never felt that the small amount of convenience it provides is worth the great loss of system security. -- Patrick Volkerding |
| |||
| On Sun, 11 May 2008, loki harfagr wrote: > On Sun, 11 May 2008 11:30:51 -0700, William Hunt wrote: >> i'm looking for a util which, given an integer argument N, can print the >> date of the day N days ago. example: [...] > You didn't say your reasons why you wouldn't > use the 'fuzzy' date like: > > $ date --date "yesterday" > Sun May 10 20:43:55 CEST 2008 > $ date --date "2 days ago" > Fri May 9 20:44:06 CEST 2008 :*) because the man page does not even mention fuzzy dates. And, 'strings /bin/date' doesn't produce any such keywords. And, 'info date' only tells me to use 'info date' for the full documentation, LOL. Thanks, Loki! -- William Hunt, Portland Oregon USA |
| |||
| On Sun, 11 May 2008, Thomas Overgaard wrote: > William Hunt wrote : > >> Does someone want to smack me with a Clue ? > > Try 'date --date=-12days' Excellent - that's is -exactly- the clue i needed. So: #!/bin/bash date --date=${1:-0}day +%Y/%m/%d # the end. Thanks, Thomas! -- William Hunt, Portland Oregon USA |
| |||
| On Sun, 11 May 2008, Bartosz Oudekerk wrote: > William Hunt <wjh@prv8.net> typed on 2008-05-11: >> i'm looking for a util which, given an integer argument N, >> can print the date of the day N days ago. > > #!/bin/bash > date -d "${1} days" +%Y/%m/%d > But, note that if $1 is null, we get tomorrow's date ... but ${1:-0} works in all cases. ( I rotate and archive logfiles by day, /var/log/YYYY/DD/MM/... , and this might make it easier now to get at yesterday's logs, /var/log/$(day -1)/... ) hanks, Bartosz. -- William Hunt, Portland Oregon USA |
| |||
| Hallo, William, Du meintest am 11.05.08: >>> i'm looking for a util which, given an integer argument N, can >>> print the date of the day N days ago. example: > [...] > :*) because the man page does not even mention fuzzy dates. > And, 'strings /bin/date' doesn't produce any such keywords. > And, 'info date' only tells me to use 'info date' for the > full documentation, LOL. Try info date Node "Examples of date" or (better readable) pinfo date You can find "pinfo" at "slacky.eu". Viele Gruesse Helmut "Ubuntu" - an African word, meaning "Slackware is too hard for me". |
| ||||
| On Mon, 12 May 2008 08:07:00 +0200, Helmut Hullen wrote: > Hallo, William, > > Du meintest am 11.05.08: > >>>> i'm looking for a util which, given an integer argument N, can print >>>> the date of the day N days ago. example: > >> [...] > >> :*) because the man page does not even mention fuzzy dates. And, >> 'strings /bin/date' doesn't produce any such keywords. And, 'info date' >> only tells me to use 'info date' for the full documentation, LOL. > > Try > > info date > Node "Examples of date" ITYM: info coreutils g Examples of date ;-) > > or (better readable) > > pinfo date > > You can find "pinfo" at "slacky.eu". > > Viele Gruesse > Helmut > "Ubuntu" - an African word, meaning "Slackware is too hard for me". ITYM: -- "Ubuntu" - a .sig breaker meaning "my spacebar just broke" |