Adding hours to current date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding hours to current date
# 1  
Old 02-22-2012
Adding hours to current date

Hi,

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

thanks in advance
# 2  
Old 02-22-2012
This works on my GNU bash:
Code:
date -d "+5 hours"

# 3  
Old 02-22-2012
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 06:03 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 02-22-2012
This adds 5 hours to current time.
Code:
perl -e '$x=localtime(time+(5*3600));print $x'

This User Gave Thanks to balajesuri For This Post:
# 5  
Old 02-22-2012
hey thanks!! i did the same but in multiple lines.. you are greatSmilie
# 6  
Old 02-22-2012
In nawk ..
Code:
$ nawk 'BEGIN{print "0t"srand()+(5*3600)"=Y"}' | /usr/bin/adb

# 7  
Old 02-22-2012
hey jayan,
i dont have any idea about these AWK.. can you explain your statement..?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to replace a parameter(variable) date value inside a text files daily with current date?

Hello All, we what we call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to... (1 Reply)
Discussion started by: pradeepp
1 Replies

2. Linux

How to calculate the quarter end date according to the current date in shell script?

Hi, My question is how to calculate the quarter end date according to the current date in shell script? (2 Replies)
Discussion started by: Divya_1234
2 Replies

3. Shell Programming and Scripting

Adding 48 hours to DateTime

Hey Guys, I have looked for a solution throughout the forum for my particular question, but I cant find one. So I'm sorry if I overlooked it. I need to be able to 48 add hours to a particular DateTime string. I have a variable named $startTime I would like to be able to take that... (1 Reply)
Discussion started by: chagan02
1 Replies

4. UNIX for Dummies Questions & Answers

Adding hours and minutes to current date (Only to date not to time)

Hi, I want to add some hours and minutes to the current date. For example, if the current date is "July 16, 2012 15:20", i want to add 5 hours 30 minutes to "July 16, 2012 00:00" not to "July 16, 2012 15:20". Please help. Thanks! (4 Replies)
Discussion started by: manojgarg
4 Replies

5. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

6. UNIX for Dummies Questions & Answers

Execute crontab for every 4 hours and begin from current time

I want to add a crontab entry which should execute for every 4 hours and that 4 hours calculation should begin from the current time. Normally if I set the crontab entry like this, 00 */4 30 05 * root date >>/tmp/cronout The above will execute the date command for every 4 hours like... (7 Replies)
Discussion started by: Ganeshwari
7 Replies

7. Windows & DOS: Issues & Discussions

Adding or subtracting days from current date in batch script

Hi, I'm writing an batch file to create report In the batch file iam passing two arguments:startdate and finishdate Ex: startdate=07-sep-2009 finishdate=07-sep-2011 I need to have script that takes command line argument as input and gives me out currentdate last year and current date... (2 Replies)
Discussion started by: anand1773
2 Replies

8. Shell Programming and Scripting

Date One Week Ago From Given Date, Not From Current Date

Hi all, I've used various scripts in the past to work out the date last week from the current date, however I now have a need to work out the date 1 week from a given date. So for example, if I have a date of the 23rd July 2010, I would like a script that can work out that one week back was... (4 Replies)
Discussion started by: Donkey25
4 Replies

9. Shell Programming and Scripting

Reading Hours and Minutes from file and comparing with current

Hi, Time till when the application should run is indicated in a file. First line is hour and second line is minute. file: 10 55 Means my application should run till 10:55. Now in a shell script, i am trying to make that logic but with no luck. min=`tail -n 1 /file_with_time`... (1 Reply)
Discussion started by: SGD
1 Replies

10. UNIX for Dummies Questions & Answers

How to use datecalc for adding hours

Hello: I need to generate two datetimestamps in one hour apart. the start date is 05262008000000 then generate the following dates 05262008010000 05262008020000 05262008030000 ... ... ... ... ... ... 05262008230000 05272008000000 05272008010000 05272008020000 05272008030000 ...... (5 Replies)
Discussion started by: ucbus
5 Replies
Login or Register to Ask a Question