Operating System - HP-UX
1752794 Members
5894 Online
108789 Solutions
New Discussion юеВ

Get Current Time + 10 Minutes

 
Rob Bell
New Member

Get Current Time + 10 Minutes

Hello,

Does anyone know a simple way to find the time that is 10 minutes from
now? I have a shell script that needs to calculate the current time
plus 10 minutes and use that in a user message. I know I can use the
'date' command to get the system time in whatever format I want, but I
don't know how to add 10 minutes to the current time without parsing
through each digit and adding all the logic to do it.

Thanks,
Rob
2 REPLIES 2
Dan Hull
Regular Advisor

Re: Get Current Time + 10 Minutes

There is a somewhat fudgy way of doing this that's easier than fully parsing
everything. I haven't worked it all the way through in quite awhile, but you
can start with this:

# echo `date +%M` + 10 | bc

The bc command will do the math, so you end up sending the command "## + 10"
through it for simple addition. Note that the date command is surrounded by
ticks, not apostrophes. This causes it to execute the date command.

This will produce a final number that is the minutes (10 from now). As long as
it's less than 60, you just echo the hour onto the front. If it's 60 or
greater, subtract 60 and echo the hour +1 in front of it (again using bc).

Of course, this works much better if you use 24-hour time. You won't need to
worry about the midnight hour unless you have people working all night.
Anthony Goonetilleke_1
Regular Advisor

Re: Get Current Time + 10 Minutes

I know this is slightly off topic but you might consider using perl to write
your scripts. Date routines and many other things are much easier and it also
gives you more flexibility. For example to add 10 mins on to the current time

#!/bin/perl
$newtime = localtime (time + 10*60 );
print ("$newtime");

you can basically add or subtract seconds/mins/hours/days at will.
Hope this helps.