Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-22-2012
Registered User
 

Join Date: Feb 2012
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Adding hours to current date

Hi,

any idea how to add hours to current date in unix.

thanks in advance
Sponsored Links
    #2  
Old 02-22-2012
balajesuri's Avatar
#! /bin/bash
 

Join Date: Apr 2009
Location: India
Posts: 1,019
Thanks: 9
Thanked 285 Times in 277 Posts
This works on my GNU bash:

Code:
date -d "+5 hours"

Sponsored Links
    #3  
Old 02-22-2012
Registered User
 

Join Date: Feb 2012
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
didn't worked on my solaris


Code:
date -d "+5 hours"
date: illegal option -- d
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]

---------- Post updated at 01:12 PM ---------- Previous update was at 01:06 PM ----------

any idea if i can use perl to add 5 hrs to the current date

Last edited by Franklin52; 02-22-2012 at 05:03 AM.. Reason: Please use code tags for code and data samples, thank you
    #4  
Old 02-22-2012
balajesuri's Avatar
#! /bin/bash
 

Join Date: Apr 2009
Location: India
Posts: 1,019
Thanks: 9
Thanked 285 Times in 277 Posts
This adds 5 hours to current time.

Code:
perl -e '$x=localtime(time+(5*3600));print $x'

Sponsored Links
    #5  
Old 02-22-2012
Registered User
 

Join Date: Feb 2012
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
hey thanks!! i did the same but in multiple lines.. you are great
Sponsored Links
    #6  
Old 02-22-2012
Registered User
 

Join Date: Jul 2008
Location: India
Posts: 757
Thanks: 6
Thanked 164 Times in 158 Posts
In nawk ..

Code:
$ nawk 'BEGIN{print "0t"srand()+(5*3600)"=Y"}' | /usr/bin/adb

Sponsored Links
    #7  
Old 02-22-2012
Registered User
 

Join Date: Feb 2012
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
hey jayan,
i dont have any idea about these AWK.. can you explain your statement..?
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Delete a row from a file if one column containing a date is greater than the current system date chumsky UNIX for Dummies Questions & Answers 4 07-06-2011 02:07 AM
Execute crontab for every 4 hours and begin from current time Ganeshwari UNIX for Dummies Questions & Answers 7 05-31-2011 12:34 PM
Adding or subtracting days from current date in batch script anand1773 Windows & DOS: Issues & Discussions 2 01-12-2011 02:38 PM
Reading Hours and Minutes from file and comparing with current SGD Shell Programming and Scripting 1 03-17-2009 01:12 PM
How to use datecalc for adding hours ucbus UNIX for Dummies Questions & Answers 5 06-03-2008 04:48 PM



All times are GMT -4. The time now is 04:56 AM.