How to Increment or add minutes???;-)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Increment or add minutes???;-)
# 8  
Old 08-19-2008
Quote:
Originally Posted by palsevlohit_123
timehh=`date -u '+%H'`
timemm=`date -u '+%M'`
curr_time="$timehh:$timemm"
timemm=`expr $timemm + 1`
new_time="$timehh:$timemm"
echo "$curr_time === $new_time"
this won't work if current time is 12:59 and so on.. because after addition it becomes 12:60 instead of 13:00
# 9  
Old 08-19-2008
Quote:
Originally Posted by palsevlohit_123
timehh=`date -u '+%H'`
timemm=`date -u '+%M'`
curr_time="$timehh:$timemm"
timemm=`expr $timemm + 1`
new_time="$timehh:$timemm"
echo "$curr_time === $new_time"
Thanks a lot palsevlohit_123 !!!!

It helped me a lot..
# 10  
Old 08-19-2008
it really helped you?? did you tried when min is 59??
# 11  
Old 08-19-2008
Quote:
Originally Posted by vidyadhar85
it really helped you?? did you tried when min is 59??
Yes,...It really helped me.
i used a condition for that.(when min=59)incrementing hour...etc..

Regards
P
# 12  
Old 08-19-2008
If you have ksh93 you can use the %T option to printf to manipulate the date
Code:
$ newtime=$(printf "%(%H:%M)T\n" "now + 1 minute")

# 13  
Old 08-19-2008
Thanks for reply..
but
......its not working in my machine....

Any other solution ...?
# 14  
Old 08-19-2008
MySQL

Quote:
Originally Posted by prashant43
Hi all,

I want to add a minute to present time.
E.g:
if present time is 09:55, I want to make it 09:56.

Please help!!

I tried below script

#!/bin/ksh

timeut=`date -u '+%R'`
let timeut1=$timeut + 1
echo "timeut1 = $timeut1"


Regards
PrashantSmilie
Finally using the below for my query..........Thanks for all who ever replied and gave their valuable answers...

#!/bin/ksh
timehh=`date -u '+%H'`
timemm=`date -u '+%M'`
if test $timemm -eq 59
then
timehh=`expr $timehh + 1`
timemm=`expr $timemm - 1`
fi
curr_time="$timehh:$timemm"
timemm=`expr $timemm + 1`
new_time="$timehh:$timemm"
echo "$curr_time === $new_time"


Regards
Prashant
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

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

5. Shell Programming and Scripting

[Solved] How to increment and add variable length numbers to a variable in a loop?

Hi All, I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies

6. Shell Programming and Scripting

[Solved] Working with date (add minutes using variables)

Dear all, today I'm scratching my head with a simple (I believe) issue. Working with date is quite simple, so if I Need to add some seconds to current time, I'll use: date --date='+30 seconds' +"%Y-%m-%d %H:%M:%S"But, how to pass the value to add from a variable? I tried the following without... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

7. Shell Programming and Scripting

Add minutes in Datetime Variable in Unix

Hi, New to scripting. I have datetime as a String and I need to add some hours/minutes in to that. 21/10/2009 23:00:00 After adding 180 minutes; it will look like this 22/10/2009 02:00:00 Regards, Vikas Mahajan (9 Replies)
Discussion started by: vikas482
9 Replies

8. Shell Programming and Scripting

Increment value (starttime)

Hi All, I have created a script... #!/bin/sh datafile=ABC2008101601.OUT indfile=ABCIND20081016.1.OUT waittime=600 starttime=0 while do if then echo "Indicator file has arrived." break else sleep 10; ((starttime=$starttime+10)) echo $starttime (2 Replies)
Discussion started by: Amit.Sagpariya
2 Replies

9. 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

10. Shell Programming and Scripting

add increment field when first field changes

Hi I have a file that looks like the following: Name1 aaa bbbb Name1 ffd hhghg Name1 dffg ghhhh Name2 rtrt dfff Name2 rrtfr tgtt Name2 dsddf gfggf Name2 ffffg gfgf NAme3 fdff ghhgh Is it possible to format it so that a number... (2 Replies)
Discussion started by: azekry
2 Replies
Login or Register to Ask a Question