The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



Thread: Add Date
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 01-20-2004
Ygor's Avatar
Ygor Ygor is offline
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,243
The shell is not the best tool for date/time arithmetic. Assuming you have perl...
Code:
#!/usr/bin/ksh
touch -t $(sed 's/\(..\)$/.\1/' payt_date.dat) payt_date.dat
perl -e '
  ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
    $atime,$mtime,$ctime,$blksize,$blocks)=stat("payt_date.dat");
  ($ss,$mm,$hh,$DD,$MM,$YY)=localtime($mtime+600);
  printf "%04d%02d%02d%02d%02d%2d\n",$YY+1900,$MM+1,$DD,$hh,$mm,$ss;
' > payt_date_plus_ten.dat
cat payt_date_plus_ten.dat
20031007202031