Add Date


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Add Date
# 1  
Old 01-19-2004
Add Date

I have a file with date and time in it YYYYMMDDHHMISS

cat payt_date.dat
20031007201031

and I need to add 10minutes

Any ideas?
# 2  
Old 01-19-2004
Is this what you want? If not, explain more about what you're trying to do...

sed 's/20031007201031/20031007202031/g' payt_date.dat
# 3  
Old 01-19-2004
the date field could be any date/time , I need a shell that works out the date + 10 minutes . I should have explained this.
# 4  
Old 01-20-2004
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
# 5  
Old 01-20-2004
:)

thanks Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to add a date column (today's date) in file

Hi I have file with number status and date1 and date1 field, want add a column today between column date1 and date2. file1.txt number status date1 date2 ===== ==== === ===== 34567 open 27/06/13 28/06/13 45678 open 27/06/13 28/06/13 43567 open 27/06/13 28/06/13 ... (1 Reply)
Discussion started by: vijay_rajni
1 Replies

2. Shell Programming and Scripting

Add current date and time

i have file 1.txt asdas|csada|13|03|10|04|23|A1|canberra sdasd|sfdsf|13|04|26|23|28|A1|sydney i want to add today's date and time in the end of each row expected output asdas|csada|13|03|10|04|23|A1|canberra|130430|1358 sdasd|sfdsf|13|04|26|23|28|A1|sydney|130430|1358 todays date... (10 Replies)
Discussion started by: radius
10 Replies

3. Shell Programming and Scripting

LINUX ---> Add one date to a date variable

Hi All, I am trying to add one day to the busdt variable i am extracting from a file (DynamicParam.env). I am deriving the busdt as below. Is there any function which I can use to derive as below. If busdt=20120910, then the new derived variable value should be 20120911 If... (2 Replies)
Discussion started by: dsfreddie
2 Replies

4. Emergency UNIX and Linux Support

Convert string to date and add 1

Hi All, I want to convert string in format YYYYMMDD(20120607) to date in unix and add 1 day to it and convert back to string in format YYYYMMDD. Please help. (4 Replies)
Discussion started by: cns1710
4 Replies

5. UNIX for Dummies Questions & Answers

Unable to add date to current date.

Hi, I am trying to display future date from the current date but unable to do so in UNIX (not in PERL). For eg: if today is March 5 then I want a variable wherein I can store Mar 7 date, but unable to get the future date from the current date. I have tried many possible ways as mentioned below... (11 Replies)
Discussion started by: amit.mathur08
11 Replies

6. UNIX for Dummies Questions & Answers

Perl add one minute to the given date

Hello Gurus, We have a query where we need to add one minute ( also we need to add 12 hrs in another query) to given date. we tried using some functionalities like 'perl -e @d= $run_dt + 600' . however we were not succeeded. Basically issue is we get date in following format "May18... (9 Replies)
Discussion started by: sandeeppvk
9 Replies

7. UNIX for Advanced & Expert Users

date need to be add in the subject of the mail.

Hi Am fetching a weekly report pf data..once i fetched the data i need a sent report by mail. In the subject of that mail i want to sent a message like.. SUBJECT :The report had been fetched from (01/12/08 to 07/12/08). I need to send a report like this every week with that particular... (2 Replies)
Discussion started by: bobprabhu
2 Replies

8. UNIX for Dummies Questions & Answers

Add a day to a given date

Hi, I have a date field which is a variable field being passed to the script from outside. I need to know how i can add 1 day to it. I have seen example of date subtraction but while adding each time date reaches 31 or 30 i have to put if else condition. Or for leap year also. Kindly let... (4 Replies)
Discussion started by: pallet
4 Replies

9. Shell Programming and Scripting

Add Date as part of file name

How can I add date in format yyyymmdd to my existing file name ? For example my file name is test.dat then i want it to be test.datyyyymmdd (3 Replies)
Discussion started by: amsh76
3 Replies

10. UNIX for Dummies Questions & Answers

Add date to a filename

Hi I want to add the date to a filename in a script I have. So I want exp myfile01-FEB-2005.dmp How do I get the 01-FEB-2005 in there? Cheers Rich (3 Replies)
Discussion started by: richard1975
3 Replies
Login or Register to Ask a Question