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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk time 1

Status
Not open for further replies.

lambros

Programmer
Oct 10, 2002
42
0
0
US
Hi all,

How do I write a loop / statement to subtract 1 second from this;

05/Nov/2002:15:10:13

Thanks,
L.
 
There might be an easy way but here is a brute force method.

BEGIN {
FS = ":"
m1["Jan"]="Dec";m1["Feb"]="Jan";m1["Mar"]="Feb"
m1["Apr"]="Mar";m1["May"]="Apr";m1["Jun"]="May"
m1["Jul"]="Jun";m1["Aug"]="Jul";m1["Sep"]="Aug"
m1["Oct"]="Sep";m1["Nov"]="Oct";m1["Dec"]="Nov"
m2["Jan"]=31;m2["Feb"]=28;m2["Mar"]=31
m2["Apr"]=30;m2["May"]=31;m2["Jun"]=30
m2["Jul"]=31;m2["Aug"]=31;m2["Sep"]=30
m2["Oct"]=31;m2["Nov"]=30;m2["Dec"]=31
}
{
split($1,dt,"/")
dd = dt[1]
mt = dt[2]
yy = dt[3]
hh = $2
mm = $3
ss = $4-1;
if (ss < 0) {
ss = 59
mm--
if (mm < 0) {
mm = 59
hh--
if (hh < 0) {
hh = 23
dd--
if (dd < 1) {
mt = m1[mt]
dd = m2[mt]
if (mt==&quot;Feb&quot; && yy%4 == 0 && (yy%100 != 0 || yy%400 == 0)) dd=29
if (mt==&quot;Dec&quot;) yy--
}
}
}
}
print dd &quot;/&quot; mt &quot;/&quot; yy &quot;:&quot; hh &quot;:&quot; mm &quot;:&quot; ss
}
~
~
~ CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top