0

I would like to know how to subtract X minutes from the current system date. I do know how to subtract hours, but I need a more flexible solution.

NEWDATE=`TZ=GMT-1 date +%y%m%d%H%M.%S` 
echo $NEWDATE
j0k
  • 22,600
  • 28
  • 79
  • 90
Simone Di Cola
  • 353
  • 5
  • 13

1 Answers1

3
# date
Tue Aug  7 17:11:01 BST 2012

# date -d "-10 minutes"
Tue Aug  7 17:01:01 BST 2012

# date -d "-10 minutes +30 seconds"
Tue Aug  7 17:01:31 BST 2012

But based on the man page, -d is not available on HP-UX. Try this one:

perl -e 'use POSIX;print strftime "%Y%m%d %H%M.%S\n",localtime time-(30*60);'
Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
  • Will HP-UX's date work with those date strings? I thought those were extensions on GNU date. – jordanm Aug 07 '12 at 16:17
  • #$^&!.. sorry.. missed the tag! @Simone Di Cola: what tools are available there? perl? awk? – Karoly Horvath Aug 07 '12 at 16:36
  • @Simone Di Cola: well, it still depends on the version your hp-ux uses. does that perl code work? `perl --version`, `awk --version`? – Karoly Horvath Aug 07 '12 at 20:11
  • [root@HUG30093 /] # perl --version This is perl, v5.8.8 built for IA64.ARCHREV_0-thread-multi (with 13 registered patches, see perl -V for more detail) – Simone Di Cola Aug 08 '12 at 07:10
  • [root@HUG30093 /] # awk --version Usage: awk [-F fs][-v Assignment][-f Progfile|Program][Assignment|File] ... [root@HUG30093 /] # which awk /usr/bin/awk – Simone Di Cola Aug 08 '12 at 07:12