Additional time to system time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Additional time to system time
# 1  
Old 06-11-2013
Additional time to system time

Hi All,

Is there any command to add additional time to date command. I need to add 5 hours to the present system time. I am getting the time by using date command.

Code:
WORKFLOW_START_TIME=`date +%m/%d/%Y\ %H:%M:%S`

Thanks
# 2  
Old 06-11-2013
Horrible, but it works...
Code:
WORKFLOW_START_TIME=$(perl -e '@t= localtime(time() + (5 *(60 * 60 )));printf "%02d/%02d/%04d %02d:%02d:%02d\n", $t[4] + 1, $t[3],$t[5]+1900, @t[2,1,0]')

This User Gave Thanks to Skrynesaver For This Post:
# 3  
Old 06-11-2013
Depending on what OS and date version you have, this might work:
Code:
date -d"+5hours" +%H:%M:%S


Last edited by RudiC; 06-11-2013 at 12:06 PM.. Reason: typo
# 4  
Old 06-11-2013
Using Korn Shell 93:
Code:
#!/bin/ksh93

printf "%(%m/%d/%Y %H:%M:%S)T\n" "exactly next 5 hour"

# 5  
Old 06-11-2013
Hi RudiC,

Its not working,

Code:
$ date
Tue Jun 11 15:31:03 GMT 2013
$ date -d"+5hours" +%H:%M:%S
date: illegal option -- d
date: illegal option -- +
date: illegal option -- 5
date: illegal option -- h
date: illegal option -- o
date: illegal option -- r
date: illegal option -- s
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]
$
$ uname
SunOS

Shell -

Code:
$ echo $0
-ksh


Last edited by nag_sathi; 06-11-2013 at 12:33 PM.. Reason: added shell type
# 6  
Old 06-11-2013
date -d is a feature so obvious and handy you'd think it's everywhere, but isn't. It's a GNU/Linux thing mostly.
# 7  
Old 06-11-2013
Another perl approach:
Code:
WORKFLOW_START_TIME=$(perl -e 'use POSIX qw(strftime); print strftime "%m/%d/%Y %H:%M:%S",localtime(time()+ 3600*5);')

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Linux

Time: Hwclock and System Time

Hey everyone. Upon studying linux trying to learn it inside and out, I'm reading about the issue of time. Hardware clock time vs the more commonly referenced System Time. What causes the two to grow apart, and what causes the time itself to stray away from UTC? at present my clock is a second and... (1 Reply)
Discussion started by: Lost in Cyberia
1 Replies

2. Shell Programming and Scripting

what would a script include to find CPU's %system time high and user time high?

Hi , I am trying to :wall: my head while scripting ..I am really new to this stuff , never did it before :( . how to find cpu's system high time and user time high in a script?? thanks , help would be appreciated ! :) (9 Replies)
Discussion started by: sushwey
9 Replies

3. Solaris

System time and Cron time stamp not matching

On Solaris 10 server the system date won't match with the timestamp on files created by a cron jobs, Please help here is what i get when i check for system date infodba-ie10ux014:/tcpdv1_ie10/tcadmin/bin\n\r-> date Tue Apr 24 15:27:43 GMT 2012at same time i executed a cron job, and checked... (4 Replies)
Discussion started by: karghum
4 Replies

4. Shell Programming and Scripting

How to get system time

I am trying to write a script which will compare the start time of a process with the current time. but I am having trouble finding the command to get the current time. (3 Replies)
Discussion started by: akabir77
3 Replies

5. Solaris

getting time independent of system time in solaries

i am using function gethrtime() in sun solaries to get the time independent of the system time.Problem with this function is if we restart the system time will change to '0'.is there any other way to resolve this problem. thanks & regards suresh (3 Replies)
Discussion started by: suresh_rtp
3 Replies

6. Shell Programming and Scripting

System time comparison to fixed defined time

I have a requirement of checking the current system time and performing certain actions in a shell script. example: if the current system time is greater than 1400 hrs, then perform step 1,2,3 if the current system time is greater than 1000 hrs, then perform step 1,2 if the current system time... (2 Replies)
Discussion started by: zainravi
2 Replies

7. UNIX for Advanced & Expert Users

Last system installation time

Hi, What is the best way to find the last installation time of an unix based systems?Please advise Thanks Nagarajan G (7 Replies)
Discussion started by: ennstate
7 Replies

8. Shell Programming and Scripting

System time

Hey all, I need to write a script which will invoke another script everything 5 minutes until certain time is reached (say 4:00 pm). Can anyone give me some pointers please? Thanks! (1 Reply)
Discussion started by: mpang_
1 Replies

9. UNIX for Dummies Questions & Answers

System Startup Time

Hi all, Can anyone tell me how to find the System Startup time. Currently I am using "who -b" to get last reboot time. I wanted to know is there any log file for SCO Openserver 5, in which all this sort of imformations are kept. I have tried searching the forum with words like "WHO... (6 Replies)
Discussion started by: shoeb_syed
6 Replies
Login or Register to Ask a Question