subtract minutes from time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting subtract minutes from time
# 8  
Old 04-21-2010
Quote:
Originally Posted by tomjones
i have the time 20100421043335 in format (date +%Y%m%d%H%M%S),and i want to be able to get the previous time 2 minutes ago,which is

20100421043135
This probably is related to the other question you asked, and since you've used Perl in the other one, I guess you can solve this problem by using the Date::Calc Perl module -

Code:
perl -M"Date::Calc qw(:all)" -le '$x="20100421043335"; printf("%4d%02d%02d%02d%02d%02d\n",Add_Delta_DHMS(unpack("A4A2A2A2A2A2",$x),0,0,-2,0))'

Test run:

Code:
$
$
$ perl -M"Date::Calc qw(:all)" -le '$x="20100421043335"; printf("%4d%02d%02d%02d%02d%02d\n",Add_Delta_DHMS(unpack("A4A2A2A2A2A2",$x),0,0,-2,0))'
20100421043135
$
$

tyler_durden
# 9  
Old 04-21-2010
how do i get or start using the date cal per module
# 10  
Old 04-21-2010
Quote:
Originally Posted by tomjones
how do i get or start using the date cal per module
From the one-and-only stop aka CPAN (the Comprehensive Perl Archive Network, in case you didn't know).

Installing CPAN Modules

tyler_durden

Ok, that was the short answer.

I don't know what OS you are on, but if it's a Linux flavor or Windows, then it's pretty easy. CPAN, besides the website, is a Perl module as well and is packaged as an rpm or deb file for Linux. You can use your Linux flavor's package-manager program (yum, apt-get, yast etc.) to install cpan. Once it is done, log in as root and run the cpan command, which opens up the cpan shell. Installing any Perl module from there is just a matter of firing the "install <module_name>" command.

Windows is easier than that. ActiveState has its own package-manager for Perl called "ppm". It's a graphical tool and extremely easy to navigate. You fire it up with the "ppm" command. To install a module, select it from the list and click on the "Install" button. (I've never used Strawberry Perl on Windows, so can't comment on that.)

If you cannot install by either of these methods, then life would be tough. You'll have to build and compile from the sources, and I'd suggest you talk to your SysAdmin about it.

HTH,
tyler_durden

Last edited by durden_tyler; 04-21-2010 at 07:48 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check file creation Time minutes and if file older then 5 minutes execute some stuff

Hello all, Info: System RedHat 7.5 I need to create a script that based on the creation time, if the file is older then 5 minutes then execute some stuff, if not exit. I thought to get the creation time and minutes like this. CreationTime=$(stat -c %y /tmp/test.log | awk -F" " '{ print... (3 Replies)
Discussion started by: charli1
3 Replies

2. Shell Programming and Scripting

Subtract time in two line

INPUT: 16:45:51 10051 77845 16:45:51 10051 77845 16:46:52 10051 77846 16:46:53 10051 77846 Match the last PID then subtract second line time with first line. Please help me with any command or script. (3 Replies)
Discussion started by: vivekn
3 Replies

3. UNIX for Dummies Questions & Answers

Subtract minutes from date

Hi, I am reading a particular date from a file using below command WFLWDATE=$(sed '2q;d' FileA.prm) The echo command outputs the correct date in variable WFLWDATE Now I want to subtract 5 minutes from this variable. I am on AIX and unable to get anything working as expected. Can you... (1 Reply)
Discussion started by: vrupatel
1 Replies

4. Shell Programming and Scripting

Date command - subtract from given time

the given time is: 12:13:00 how do i subtract a 10 minutes from any given time? date '12:13:00' '-10 min' also tried this: date +12:13:00 '-10 min' (2 Replies)
Discussion started by: SkySmart
2 Replies

5. Shell Programming and Scripting

Add or Subtract the hours,minutes or seconds in the the time variable

Hello All, I am working on script where I need to add hours,minutes or seconds in the time.Time is not the current but it could be future time.I thought I can store that time in variable and add hours.minutes or second but I am not able to add that in the time that is stores in a variable. Time... (9 Replies)
Discussion started by: anuragpgtgerman
9 Replies

6. Shell Programming and Scripting

Subtract two rows (in Time format)

Hello all, I have written sth like this: #!/bin/bash grep -e XXX -e YYYY myfile.log | grep -v ZZZ | awk '{print $1 " " $2 ";" $3 ";" $9 ";" $11}' > myfile.csv sed -i '1iDate;Time;From;To' myfile.csv => it is clear that it converts log to csv and add a header. Now I want to subtract row... (4 Replies)
Discussion started by: frhling
4 Replies

7. Shell Programming and Scripting

How to subtract time by 10 minutes in datecalc tool

Hi guys. I am trying to subtract 10 minutes from the current Unix system date and time. I have the datecalc provided here but it is mainly the date and not the time. Please check on how can i subtract 10 minutes from the current time using datecalc or any other shell scripting that will... (2 Replies)
Discussion started by: bantiloe
2 Replies

8. Shell Programming and Scripting

Perl - Extract 12 hour time, convert to 24 and subtract 15 minutes?

OK, I am by no means a programmer... I have been given the task to do some automation scripts. I have got most of it working from snippets I have found on the Web. One requirement has me stumped. The initial timing file created by the user is a comma delimited in the following format.... (4 Replies)
Discussion started by: autotuner
4 Replies

9. Shell Programming and Scripting

Add/Subtract Time

need some help on the below requirement: File1: SV,22,20100501140000,JFK,RUH SV,29,20100501073000,BOM,RUH SV,29,20100501073000,SIN,RUH third filed is datetime which is of the format (yyyymmddhh24miss) File2 JFK,+,0500 BLR,-,0530 SIN,-,0800 for every line of file 1, take 4... (9 Replies)
Discussion started by: ssantoshss
9 Replies

10. Shell Programming and Scripting

Subtract Time

Hello, Im writing a script using the ksh shell. I have 2 variables in the script: CURRTIME PREVTIME Example, if CURRTIME=13:00, I want to somehow calculate what the time was an hour ago so that PREVTIME=12:00 Right now I have the following: CURRTIME=`date +%H:%M` How can I... (4 Replies)
Discussion started by: xadamz23
4 Replies
Login or Register to Ask a Question