Unix Technical Forum

OT: util for relative date?

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 ...


Go Back   Unix Technical Forum > Unix Operating Systems > Slackware Linux Support

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-11-2008, 08:41 PM
William Hunt
 
Posts: n/a
Default OT: util for relative date?


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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-11-2008, 08:41 PM
loki harfagr
 
Posts: n/a
Default Re: OT: util for relative date?

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-11-2008, 08:41 PM
Thomas Overgaard
 
Posts: n/a
Default Re: OT: util for relative date?


William Hunt wrote :

> Does someone want to smack me with a Clue ?


Try 'date --date=-12days'
--
Thomas O.

This area is designed to become quite warm during normal operation.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-12-2008, 09:08 AM
Bartosz Oudekerk
 
Posts: n/a
Default Re: OT: util for relative date?

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-12-2008, 09:08 AM
William Hunt
 
Posts: n/a
Default Re: OT: util for relative date?

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 05-12-2008, 09:08 AM
William Hunt
 
Posts: n/a
Default Re: OT: util for relative date?

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-12-2008, 09:08 AM
William Hunt
 
Posts: n/a
Default Re: OT: util for relative date?

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 05-12-2008, 09:08 AM
Helmut Hullen
 
Posts: n/a
Default Re: OT: util for relative date?

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".

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 05-12-2008, 09:08 AM
loki harfagr
 
Posts: n/a
Default Re: OT: util for relative date?

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"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:36 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com