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

add and substract dates in awk

Status
Not open for further replies.

Shelllearner

Programmer
Oct 18, 2006
2
CR
Hi, I am working on a awk program and I have to get current time (which I am doing with date) and add and substract 4 days in order to shearch those dates in a file (searching in a file is not problem).
I really appreciate your help!!!
 
Hi

If you have [tt]gawk[/tt], is quite easy :
Code:
[blue]master #[/blue] awk -vd=[green][i]100[/i][/green] 'BEGIN{print "now is",strftime("%Y-%m-%d %H:%M:%S",systime());print d,"days is",strftime("%Y-%m-%d %H:%M:%S",systime()+d*24*60*60)}'
now is 2006-10-20 10:06:56
100 days is 2007-01-28 09:06:56

[blue]master #[/blue] awk -vd=[green][i]-100[/i][/green] 'BEGIN{print "now is",strftime("%Y-%m-%d %H:%M:%S",systime());print d,"days is",strftime("%Y-%m-%d %H:%M:%S",systime()+d*24*60*60)}'
now is 2006-10-20 10:06:59
-100 days is 2006-07-12 10:06:59

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top