Minus 5 minutes


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Minus 5 minutes
# 1  
Old 06-26-2014
Minus 5 minutes

Hi,

I need to subtract 5 minutes from the date. Example

$date +"%Y-%m-%d-%H.%M.%S" displays 2014-06-26-06.06.38

I want to show it as 2014-06-26-06.01.38 (5 mins are subtracted from date)

Any help would be appreciated. I am currently on AIX version 6.1

-Vrushank
# 2  
Old 06-26-2014
With the fairly common -d flag not being available for AIX, I've cobbled together this:-
Code:
date
perl -e 'print scalar localtime(time - 300), "\n";'

THis gives you the calculation, but the output may not be correct. Is this sufficient or do you need the format?



Robin
These 2 Users Gave Thanks to rbatte1 For This Post:
# 3  
Old 06-26-2014
Thanks Robin, but I need it in "%Y-%m-%d-%H.%M.%S" format

Regards,
Vrushank Patel

Last edited by vbe; 06-26-2014 at 08:57 AM..
# 4  
Old 06-26-2014
Let's try this then:-
Code:
date +%Y-%m-%d-%H.%M.%S
perl -e 'use POSIX qw(strftime);print scalar(strftime "%Y-%m-%d-%H.%M.%S" , localtime(time - 300)), "\n";'

The first date is just to show the difference.


The bold red bit is the seconds to set the clock back, so you can adjust this as you may need.

It seems to work for me on AIX 4.3.3, 5.1 and 6.1

Can anyone suggest a neater way of doing this?

Robin
These 2 Users Gave Thanks to rbatte1 For This Post:
# 5  
Old 06-26-2014
Thanks Robin. That seems to be working as expected at my end. Thank you very much
# 6  
Old 06-26-2014
You are welcome for the answer and I forgot to say welcome to the forum.

Thanks for the question. Perhaps others will find it useful in future. I learned something working it out too.

Smilie



Robin
# 7  
Old 06-26-2014
Quote:
Originally Posted by rbatte1
Can anyone suggest a neater way of doing this?
Perl is about the only portable option for date math, and as perl oneliners go that's both short and readable.
These 2 Users Gave Thanks to Corona688 For This Post:
 
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

Grep a log file for the last 5 minutes of contents every 5 minutes

Hi all, System Ubuntu 16.04.3 LTS i have the following log INFO 2019-02-07 15:13:31,099 module.py:700] default: "POST /join/8550614e-3e94-4fa5-9ab2-135eefa69c1b HTTP/1.0" 500 2042 INFO 2019-02-07 15:13:31,569 module.py:700] default: "POST /join/6cb9c452-dcb1-45f3-bcca-e33f5d450105... (15 Replies)
Discussion started by: charli1
15 Replies

3. UNIX for Beginners Questions & Answers

How to convert days hours minutes seconds to minutes?

Hi, please help with below time conversion to minutes. one column values: 2 minutes 16 seconds 420 msec 43 seconds 750 msec 0 days 3 hours 29 minutes 58 seconds 480 msec 11 seconds 150 msec I need output in minutes(total elapsed time in minutes) (2 Replies)
Discussion started by: ramu.badugula
2 Replies

4. Shell Programming and Scripting

How to get a time minus 60 minutes?

Hello, date --date '-60 min ago' +'%Y-%m-%d %H:%M:%S,%3N' Above command gives the date and time minus 60 minutes but the problem i am facing is, i do not want to hardcode the value 60 it is stored in a variable var=60 now if i run below command , i get error date --date '-$var min... (3 Replies)
Discussion started by: Ramneekgupta91
3 Replies

5. Shell Programming and Scripting

Minus minus to plus

Hi there, I have a problem with arithmetic ops in awk. Here is what my script does right now. while read nr val ; do case $nr in 400) awk '$2~/eigenvectors/ {print $NF-'$val'};' input.txt >> output.txt;; esac done < frames.txtI have a file named frames.txt with two columns (nr and... (2 Replies)
Discussion started by: tobias1234
2 Replies

6. Solaris

How to show time minus 60 minutes?

In Redhat it is easy.... date --date="60 minutes ago" How do you do this in Solaris? I got creative and got the epoch time but had problems.. EPOCHTIME=`truss date 2>&1 | grep "time()" | awk '{print $3 - 900}'` echo $EPOCHTIME TIME=`perl -e 'print scalar(localtime("$EPOCHTIME")),... (5 Replies)
Discussion started by: s ladd
5 Replies

7. Shell Programming and Scripting

Minus of files

File 1 contains data : CALL_ID SOR_ID SEG_SEQ_NUM CHK_PNT_MENU_TYPE_CD PTNR_ID ACTVN_RTRN_CD PRIM_ACTVN_DCLN_REAS_CD SCNDRY_ACTVN_DCLN_REAS_CD ACTVN_SCCS_IND CARD_ACTVTD_IND MAX_ACTVN_FAILD_ATMP_IND EDW_PUBLN_ID File 2 contains data: PRIM_ACTVN_DCLN_REAS_CD... (3 Replies)
Discussion started by: ysvsr1
3 Replies

8. Shell Programming and Scripting

Minus of 2 files -- Please help

Hello people, awk '{print $0}' input1.txt input2.txt |sort -u Will give the union of the 2 files. Similarly what is command to get just the diff data (i.e minus) of the 2 files. Can I use the "diff" command to get just the diff data. Please let me know. Regards, Tipsy. (7 Replies)
Discussion started by: tipsy
7 Replies

9. UNIX for Dummies Questions & Answers

minus sign

why a minus sign is put for options in unix commands suggestions plz (2 Replies)
Discussion started by: trichyselva
2 Replies

10. Shell Programming and Scripting

Convert minutes to hours, minutes, seconds

How would you convert lets say a 1000 minutes to hours, minutes, seconds (1 Reply)
Discussion started by: Vozx
1 Replies
Login or Register to Ask a Question