1826235 Members
2929 Online
109692 Solutions
New Discussion

Newbie date question

 
SOLVED
Go to solution
David Yandry
Frequent Advisor

Newbie date question

Hello,

I have what I think is a very simple question. Each monday I need the date of the following Friday. Is there a command for this?

This is my first posting so I hope that I'm in the right category.

TIA, David
9 REPLIES 9
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Newbie date question

Hi David:

My date agent just went off so I guess I get to answer this one for you.

FRIDAY=$(caljd.sh $(caljd.sh -n 4))
echo "Friday = ${FRIDAY}"

You wiull need this attached script, caljd.sh.


Regards, Clay

If it ain't broke, I can fix that.
David Yandry
Frequent Advisor

Re: Newbie date question

Thank you. That worked but the output looks like "05 02 2003" but I need it to look like "2003-05-02". Is it possible to change the format or will I need to do some scripting?

David
A. Clay Stephenson
Acclaimed Contributor

Re: Newbie date question

Invoke caljd.sh with a -u option for full usage but here's your solution:

FRIDAY=$(caljd.sh $(caljd.sh -n 4))
echo "Friday = ${FRIDAY}"


becomes

FRIDAY=$(caljd.sh -S "-" -y $(caljd.sh -n 4))
echo "Friday = ${FRIDAY}"

Pretty simple, huh?



If it ain't broke, I can fix that.
David Yandry
Frequent Advisor

Re: Newbie date question

That worked great. Thanks.
David Yandry
Frequent Advisor

Re: Newbie date question

Hi again,

Now I have a different problem My script works great when I run from the shell but fails when I run it from cron. I've checked my cron entry and it looks ok.

TIA, David
A. Clay Stephenson
Acclaimed Contributor

Re: Newbie date question

This is easy. Cron has an intentionally very sparse environment. You almost certainly need to set and export PATH so that commands are found or explicitly use full pathnames for all commands within your script.

If it ain't broke, I can fix that.
Bill Douglass
Esteemed Contributor

Re: Newbie date question

Another option is to install the sh_utils package:

http://hpux.connect.org.uk/hppd/hpux/Gnu/sh_utils-2.0/

This will give your, among other things, the Gnu version of the date command. Then you can do something like:

qe2l1:/home/bdouglas> /opt/sh_utils/bin/date -d "+4 days" +%Y-%m-%d
2003-05-02

The commands are installed in /opt/sh_utils/bin and the man pages in /opt/sh_utils/man, so it is fairly easy to keep them seperate from the normal HP-UX versions of these commands.
Olivier ROBERT
Frequent Advisor

Re: Newbie date question

Hi David,

If you get GNU date, you can even use a more friendly language:

$ date --date 'next friday'

Regards,

Olivier
James R. Ferguson
Acclaimed Contributor

Re: Newbie date question

Hi David:

Many questions like yours have been answered in detail before. At the left of the Forum pages is a "search" link. You can use it to search for Forum threads matching any keyword(s) of your choice. While this is not intended to satisfy all needs, you will a wealth of hints, opinions, and often different ways of approaching a problem. Welcome to the ITRC Forum.

Regards!

...JRF...