Skip to content

Shell Date-Time Manipulation

August 24, 2012

For Solaris Date and Time Manipulations
===========================================

In one day we have 86400 Secs i.e. 24 Hrs

Half Day we have 43200 Secs i.e. 12 hrs

 1) Current date and time
=============================

maldevsrv:/opt/oracle: date

Fri Aug 24 07:36:18 EDT 2012

maldevsrv:/opt/oracle: CURR_DATE=`perl -e ‘use POSIX qw(strftime);$d = strftime “%m/%e/%Y %H:%M:%S”, localtime(time);print $d;’`

maldevsrv:/opt/oracle: echo $CURR_DATE

08/24/2012 07:36:18

 2) Add 12 Hrs ie Half day to Current date and time
===================================================

 maldevsrv:/opt/oracle: date

Fri Aug 24 07:38:47 EDT 2012

maldevsrv:/opt/oracle: START_DATE=`perl -e ‘use POSIX qw(strftime);$d = strftime “%m/%e/%Y %H:%M:%S”, localtime(time() + 43200);print $d;’`

maldevsrv:/opt/oracle: echo $START_DATE

08/24/2012 19:38:47

 3) Add 24 Hrs ie 1 Day to Current date and time
===================================================

 maldevsrv:/opt/oracle: date

Fri Aug 24 07:40:22 EDT 2012

maldevsrv:/opt/oracle: START_DATE=`perl -e ‘use POSIX qw(strftime);$d = strftime “%m/%e/%Y %H:%M:%S”, localtime(time() + 86400);print $d;’`

maldevsrv:/opt/oracle: echo $START_DATE

08/25/2012 07:40:22

 4) Add 24 Hrs i.e. 1 Day to Current date and time
===================================================

 Similarly replace 86400 with required Secs

 1) For 1 day

86400 * 1 = 86400 secs

 2) For 2 Days

86400 * 2 = 172800 secs

START_DATE=`perl -e ‘use POSIX qw(strftime);$d = strftime “%m/%e/%Y %H:%M:%S”, localtime(time() + 172800);print $d;’`

IF you need to subtract days then – 86400

 ======================================================================
Generate a logfile with date and time stamp of next 1 day from now
======================================================================

 maldevsrv:/opt/oracle: date

Fri Aug 24 07:53:04 EDT 2012

 maldevsrv:/opt/oracle: START_DATE=`perl -e ‘use POSIX qw(strftime);$d = strftime “%m.%e.%Y.%H.%M.%S”, localtime(time() + 86400);print $d;’`

maldevsrv:/opt/oracle: echo ” Hello Malesh ” > expdb_scott.log.$START_DATE

maldevsrv:/opt/oracle: ls -ltr shutdb.*

-rw-r–r–   1 oracle   dba           15 Aug 24 07:53 expdb_scott.log.08.25.2012.07.53.04

maldevsrv:/opt/oracle: cat expdb_scott.log.08.25.2012.07.53.04

Hello Malesh

You can Download the same in PDF => Solaris Date and Time Manipulations

Advertisements

From → Shell Scripts

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: