1833151 Members
3429 Online
110051 Solutions
New Discussion

Re: check date last week

 
Tomas Helsén_1
Occasional Advisor

check date last week

Hi,

Every monday i need to send database information that apply to the last 7 days. To be able to put this in a script i need to get the date value for 7 days ago.

Any one knows howto fix?
9 REPLIES 9
Oviwan
Honored Contributor

Re: check date last week

Hy

Here are several ways to do that:

http://www.faqs.org/faqs/hp/hpux-faq/section-168.html

Regards
JJ de Haas
Occasional Advisor

Re: check date last week

If this is something you need to be doing every week, just run a cronjob that does what you want and also let the cronjob write today's date somewhere.

Make sure the cronjob runs every week, so next week you can just grab the date entry that was written last week...

Cheers,
Jan.
Peter Godron
Honored Contributor

Re: check date last week

Tomas,
you can:
See "A. Clay Stephenson's Date Hammer" at bottom of page http://mirrors.develooper.com/hpux/

or
As you are running Monday to Monday, write the current date (for example: Monday 25/12/2006) into a file. Next Monday (1/1/2007) you read the earlier file and you have your date ! Once you completed your processing you overwrite the original file with the new date (i.e. 1/1/2007)
rariasn
Honored Contributor
Tomas Helsén_1
Occasional Advisor

Re: check date last week

thanks for the help
//Tomas
Peter Godron
Honored Contributor

Re: check date last week

Tomas,
it is customary to reward the efforts of the people suggesting answers to your questions with "points".

Could you please complete the thread by awarding points to helpful answers and summarising the solution for you.
This will help resolution of similar problems in the future.

Please read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.
Tor-Arne Nostdal
Trusted Contributor

Re: check date last week

Hmmm...
Sorry to see that many have forgotten the Julian date format...

This is really helpful and the basis of Clay's - Caljd scripts.

Date +%j

See: man date

/Tor-Arne
I'm trying to become President of the state I'm in...
A. Clay Stephenson
Acclaimed Contributor

Re: check date last week

Actually the "+%j" has nothing to doi with my caljd.sh and regardless of the fact that the date command might call the %j output a julian day, it is in fact NOT a julian day. Julian days are counted sequentially from 4713BCE and are used by astronomers to simplify date calculations.

To find 7 days before today in MM/DD/YYYY format:
D7BEFORE=$(caljd.sh -S "/" $(caljd.sh -p 7))
echo "7 days ago was ${D7BEFORE}"

Unlike the date %j output, this will work across year boundaries and leap years.
If it ain't broke, I can fix that.
Patrick Wallek
Honored Contributor

Re: check date last week

The 'date +%j' only returns the day number of the year in the range 001 thru 366. It is in no way a julian day and the date man page does not even have the word 'julian' anywhere in it.

For today (Dec 29, 2006):

# date +%j
363
It's the 363rd day of the year.

# caljd.sh
2454099

It's the 2,454,099 day since the count started.