Computing.Net > Forums > Unix > date command

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

date command

Reply to Message Icon

Name: netrom
Date: March 3, 2008 at 06:48:09 Pacific
OS: AIX
CPU/Ram: n/a
Product: n/a
Comment:

Hi guys, I know it may sound silly. I have this in my script:

JD=`date +%Y +%m|cut -c "4 5 6"`
echo $JD

the JD when I run it today outputs 803. Which is 8=part of year 2008, 03 is current month.

Is there a (simple) way of having outputted: 802 (that is always the year AND PREVIOUS month??).

e.g. when comes 1.1.2009, I'd like the JD output 812.

when it's 1.4.2008, I'd like to have variable JD = 803.

Please help!

Many thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: pklinger
Date: March 18, 2008 at 09:03:05 Pacific
Reply:

Referencing http://computing.net/unix/wwwboard/...

#!/bin/ksh
typeset -R3 JD
((HRS=$(date +%d)*24))
JD=$(TZ=aaa$HRS date +%y%m)
print $JD


0
Reply to Message Icon

Related Posts

See More


Moving recent files to an... find duplicate value comp...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: date command

how to calculate date (urgent) www.computing.net/answers/unix/how-to-calculate-date-urgent/5352.html

increment the seconds in the date www.computing.net/answers/unix/increment-the-seconds-in-the-date/5458.html

A week back date www.computing.net/answers/unix/a-week-back-date/7362.html