Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date command

Status
Not open for further replies.

abovebrd

IS-IT--Management
May 9, 2000
690
US
If I use the following command : date +%j
it gives me the date output in "day of the year format" 004

date +%j (returns) 004 (If the date is 01/04/01_

Does any one a way to have the date command interpet a number and give the date

004 = 01/04/01
005 = 01/05/01
006 = 01/06/01 and so on

-Danny






 
Hi Danny

You can try this command to get the date:
myserver% date +%d/%m/%y
05/01/01
 
babeo,

getting the present date is not the problem.

date +%D will give me 01/05/01

I need to generate two dates with two weeks between. Such as 01/04/01 and 12/21/00

Any thoughts on how to do that ?

-Danny






 
Just in case you didn't see my response in the General Unix Forum, Check the general forum for my response in detail.
This will do exactly what your asking for. Basically it gets the Julian date and today's date, I did the test just to verify I wasn't getting the same info, but it's probably not necessary. All you really need is the julian variable and todays date variable and echo "$julian = $usual" to get what you want.

#!/bin/ksh
JULIAN=`date +%j`
USUAL=`date +%m/%d/%y`
if [ $JULIAN != $USUAL ]; then
echo "$JULIAN = $USUAL"
else
echo "what's the date?"
fi
exit 0



d3funct
borg@pcgeek.net
The software required `Windows 95 or better', so I installed Linux.

 
d3funct,

Your script works just as described. However it's not really what I need. I need the ability to subtract 14 days from the current date and display that date.

present date - 14 = ?
01/05/01 - 14 days = 12/22/00

Something like that

Any more ideas ?


-Danny






 
TODAY=`date &quot;+%y %m %d&quot; | nawk '{split(&quot;31,31,28,31,30,31,30,31,31,30,31,30&quot;,month,&quot;,&quot;); if ($1 % 4 == 0) {month[3]=29;}; day=$3-<num days>; year=$1; mon=$2; if (day <= 0) {day+=month[$2-0]; mon=$2-1; year=$1-1} printf(&quot;%02d/%02d/%02d&quot;,day,mon,year);}'`
echo $TODAY

don't scream ouch too hard :)
 
note ... this only works if the amount to be subtracted is < 28 ...

would have to write something with a loop otherwise :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top