Adding 48 hours to DateTime


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding 48 hours to DateTime
# 1  
Old 04-19-2013
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 $startTime and add 48 hours. The variable format is ""%Y%m%d_%H00"

So currently $startTime = "20130419_1400" (Z Time)

Can I use the following command in shell somehow and just input the $startTime variable instead of the system date call?

endTime=$(date -d "48 Hours" "+%Y%m%d_%H00")
# 2  
Old 04-19-2013
Have a read of this to see if it helps:-
Korn Shell 93 Date/Time String Manipulation and Arithmetic
It is referenced in this post:-
https://www.unix.com/shell-programmin...te+calculation
There are lots of others here if you search for "date calculation"


If you are using AIX, there is also the cheat of forcing the time zone.

Code:
$ print "$TZ"
GMT0BST,M3.5.0,M10.5.0
$ date
Fri 19 Apr 16:19:41 2013
$ TZ=GMT-48BST,M3.5.0,M10.5.0
$ date
Sun 21 Apr 16:19:46 2013

I don't know how many OS variants support this.



I hope that this helps.


Robin
Liverpool/Blackburn
UK
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filename with datetime

Hello All, I need unix command to generate a file with datetime in it. For example : ABC_YYYYMMDDHH24MISS.txt Regards Biswajeet Ghosh (1 Reply)
Discussion started by: bghosh
1 Replies

2. Shell Programming and Scripting

UNIX- Adding days to datetime variable

Hello All, I have a date with timestamp stored in a variable and another variable which stores no. of days. Var1=2014-12-11 12:54:21 Var2=5 In my unix script, I have to add the no. of days stored in var2 with the var1 date. Var3=var1+var2=2014-12-16 12:54:21 Can you please advise if... (8 Replies)
Discussion started by: Nikita1981
8 Replies

3. 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

4. Shell Programming and Scripting

How to compare datetime?

Hi, To get the batch status, I will need to check if the particular job started after 5PM. if the job start time is before 5 pm, then it means that the job has not started for this particular date. I will run the script with date as argument. For eg: BS 07/10/2012 Start time from the log is... (8 Replies)
Discussion started by: ajayakunuri
8 Replies

5. Shell Programming and Scripting

Adding hours to current date

Hi, any idea how to add hours to current date in unix. thanks in advance (9 Replies)
Discussion started by: Abhijeet_Atti
9 Replies

6. Shell Programming and Scripting

datetime difference in seconds

Hi, I'm trying to find processing time of my script. Please can someone give me the commands to get the start/end time in "dd-mm-yyyy hh:mm:ss" and the differnce in seconds. Thanks! (5 Replies)
Discussion started by: dvah
5 Replies

7. Shell Programming and Scripting

datetime.pm

Hi, I'm trying to use datetime.pm function in Perl. I do not have in the library. Is there a way to get it and put it into library? Thanks, George. (1 Reply)
Discussion started by: gpaulose
1 Replies

8. Programming

SQL datetime calculations

Suppose I have a table as follows: CREATE TABLE data ( `datetime` datetime DEFAULT NOT NULL, `temperature` float DEFAULT NO NULL ); populated with temperature samples of a couple times a second. Let's say I want to find the temperatures which are 1 second apart: SELECT D1.datetime,... (3 Replies)
Discussion started by: figaro
3 Replies

9. Shell Programming and Scripting

how to list files between last 6 hours to 3 hours

Hi Frens, I want to list some files from a directory, which contains "DONE" in their name, i am receiving files every minute. In this i want to list all the files which are newer than 6 hours but older than 3 hours, of current time i dont want my list to contain the latest files which are ... (4 Replies)
Discussion started by: Prat007
4 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