how to calculate the time 10 mins ago?? unix

Hi guys,

Im trying to subtract time in ksh script. i.e. basically im querying a database and i want to get the time 10mins before hand..(from)

in ksh

CurrMin=$(date "+%M")
  
  from=`expr $CurrMin - 10`
  to=$CurrMin

however if i run this i say at 2 or 3 mins past the hour, i.e. 8:03 and trp and subtract 10 mins ie 07:53, the above will not work,

Is there any simple script or function to allow me to do this ?

There is alot of posts online, but i dont see any for what i am trying todo.

Any help would be appreciated

Thanks

If you have GNU date then

try this,

date -d'10 min ago' '+%F %H:%M:%S'

convert the time stamp to unix seconds, subtract 600 and reconvert it

from the wiki page of date:

Hi ,

Ive tried all the above however, i am getting the following. i have Solaris 10 installed. Is there any function that i could use to get the time 10 mins ago. or any suggestions:

> date -d'10 min ago' '+%F %H:%M:%S'
date: illegal option -- d
date: illegal option -- 1
date: illegal option -- 0
date: illegal option -- 
date: illegal option -- m
date: illegal option -- i
date: illegal option -- n
date: illegal option -- 
date: invalid argument -- go
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
 
> date +"%s" -d "Fri Apr 24 13:14:39 CDT 2009"
%s
> date -ud @1000000000
date: illegal option -- d
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
> 
> 

thanks

You'll either have to install GNU date or you'll need to write a program. You could use perl (if that helps). Just make sure you have the Date:Calc module.... you might be able to do something reasonable without that perl module.

You can probably build a query just using SQL, e.g. in Oracle...

SELECT *
  FROM some_view
 WHERE last_active_time > SYSDATE - (10 / 60 / 24)

Or use perl, e.g.

STAMP=$(perl -e '($ss, $mm, $hh, $DD, $MM, $YY) = localtime(time() - 600);
       printf "%04d%02d%02d%02d%02d", $YY + 1900, $MM + 1, $DD, $hh, $mm')
echo $STAMP

How to calculate unix epoch time with DC(Caulator)
--------------------------------------------------------------------------------
Hi All,
I have a similar problem:
In our code we are using below code to calculate the UNIX Epoch Time from the time stamp present in the file.
Can any one explain how the DC operates in below command and how we calculate the UNIX EPOCH time from this.
Date incide the file is 20:26:51
Output we get is 1289943554

File content:
0|0|4|472|2010-11-15 23:22:14|2010-11-15 23:30:06
0|0|3|200|2010-11-15 20:26:51|2010-11-15 20:30:11
Can you please explain.

@mithunpatel
We assume you mean the unix "dc" (desktop calculator) program.
Please post the script.