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 conversion 1

Status
Not open for further replies.

MickiG

Programmer
Jun 18, 2001
1
US
I need to convert a julian date to a mm/dd/yyyy format in a kornshell script.
 
Somethings that may work for you.....may not:
Please check out:


thread52-66450 /\/ETtoyeur Wrote this a while ago in one of the groups.....maybe it will help you.
#---------------- CUT HERE ------------------------------------
#!/bin/ksh
function JulDate
{
print $1 $2 $3 | awk '
{
y=$1; m=$2; d=$3;
if (m < 3) {y=y - 1; m=m + 12}
a=int(y / 100.0);
b=int(a / 4.0);
c=2.0 - a + b;
e=int(365.25 * (y + 4716.0));
f=int(30.6001 * (m + 1.0));
jd=c + d + e + f - 1524.5;
printf &quot;%1.1f&quot;, jd;
}'
}

function GregDate
{
print $1 | awk '
{
jd=$1;
z=jd + 0.5;
w=int((z - 1867216.25)/36524.25);
x=int(w / 4.0);
a=z + 1.0 + w - x;
b=a + 1524.0;
c=int((b - 122.1)/365.25);
d=int(365.25 * c);
e=int((b - d)/30.6001);
f=int(30.6001 * e);
dd=b - d -f;
if (e < 13.5) {mm=e - 1} else {mm=e - 13}
if (mm > 2.5) {yy=c - 4716} else {yy=c - 4715}
printf &quot;%4d %02d %02d&quot;, yy, mm, dd;
}'
}

JulDate `date +'%Y %m %d'` | read jd0
GregDate `print $jd0 | awk '{jd=$0 - 1;printf &quot;%1.1f&quot;,jd}'` | read y1 m1 d1
GregDate `print $jd0 | awk '{jd=$0 - 2;printf &quot;%1.1f&quot;,jd}'` | read y2 m2 d2
GregDate `print $jd0 | awk '{jd=$0 - 3;printf &quot;%1.1f&quot;,jd}'` | read y3 m3 d3

print &quot;Yesterday's date is $m1/$d1/$y1&quot;
print &quot;Two-days-ago's date is $m2/$d2/$y2&quot;
print &quot;Three-days-ago's date is $m3/$d3/$y3&quot;
#--------------------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top