Get date and time for past 1 hour from current date

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get date and time for past 1 hour from current date
# 1  
Old 12-21-2007
CPU & Memory Get date and time for past 1 hour from current date


I need to get the date and time for past 1 hour from the current date. Anyone know how to do so?

# 2  
Old 12-21-2007
One way:
$ perl -e '@d=localtime time()-3600; printf "%4d%02d%02d%02d%02d%02d\n", $d[5]+1900,$d[4]+1,$d[3],$d[2],$d[1],$d[0]'
# 3  
Old 12-21-2007
Another nce way is setting up a new variable (you can adjust the number of hours by changng the +n value previous day is +24)

-bash-3.00$ NEWDATE=`TZ=GMT+2 date +%Y-%m-%d" "%H:%M:%S`
-bash-3.00$ echo $NEWDATE
2007-12-21 09:57:09
-bash-3.00$ date
Fri Dec 21 11:57:17 GMT 2007

# 4  
Old 12-21-2007
if you have GNU date
# date +%Y%m%d%H%M%S -d  "1 hour ago"

# 5  
Old 12-21-2007
date -v -1H "+%Y-%m-%d %H:%M:%S"

# 6  
Old 08-29-2008
Thanks nhatch

nhatch -- That's the most elegant solution on these boards.

This is exactly what I was looking for. (How to subtract x number of hours from today's date/time.

Thanks again
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to substract date with current date and time

I have below file which contain the date in column 3,4,5 12345 open 10/10/13 10:08 PM 3 application is in java 67899 open 12/10/13 2:31 AM 2 apps can be reach 23456 open 11/9/13 2:31 AM 4 java is OK 65432 open 12/10/13 10:07 PM 9 we are... (1 Reply)
Discussion started by: vijay_rajni
1 Replies

2. Shell Programming and Scripting

Seven days past date from current date

hi all.. i want 2 know how 2 find 7days past date from current date.. when i used set datetime = `date '+%m%d%y'` i got 060613.. i just want to know hw to get 053013.. i tried using date functions but couldnt get it :( i use c shell and there is no chance that i can change that ..... (3 Replies)
Discussion started by: Rahul619
3 Replies

3. Shell Programming and Scripting

Add current date and time

i have file 1.txt asdas|csada|13|03|10|04|23|A1|canberra sdasd|sfdsf|13|04|26|23|28|A1|sydney i want to add today's date and time in the end of each row expected output asdas|csada|13|03|10|04|23|A1|canberra|130430|1358 sdasd|sfdsf|13|04|26|23|28|A1|sydney|130430|1358 todays date... (10 Replies)
Discussion started by: radius
10 Replies

4. Shell Programming and Scripting

Displaying current date time of EDT in IST time

Hi Folks, My server time is in EDT. And i am sending automated mails from that server in which i need to display the current date time as per IST (GMT+5:30). Please advice how to display the date time as per IST. IST time leads 9:30 mins to EDT. and i wrote something like below. ... (6 Replies)
Discussion started by: Showdown
6 Replies

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

6. Shell Programming and Scripting

How far is given date from current time?

give a date and time: Jun 12 21:05:16 06-12-2012 21:05:16 2012/06/12 21:05:16 How can i subtract these dates and times from the current date and time and get back the difference in seconds? a one liner like: echo "Jun 12 21:05:16" | some perl/awk programming 90900s (2 Replies)
Discussion started by: SkySmart
2 Replies

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

8. Shell Programming and Scripting

Compare file timestamp with current date. Diff must be 1 hour.

Hello, I've created the script below to compare the content of two files with a delay of an hour. After an hour, the lines that exist in both files, will be printed and executed. The script now uses a counter to countdown 50 minutes. But what I would prefer is to check the file timestamp of... (3 Replies)
Discussion started by: taipan
3 Replies

9. Shell Programming and Scripting

How to find a date which is 7 days past when given current date

hii all. I have to get the date of the 7th day past from the current date. if i give the current date as sep 3 then i must get the date as 27th of august. can we get the values from the "cal" command. cal | awk '{print $2}' will this type of command work. actually my need is if today is... (17 Replies)
Discussion started by: ladtony
17 Replies

10. Shell Programming and Scripting

param as current date+time

Hi All, I need to pass param on aix "errpt -a -s MMDDHHMMYY -e MMDDHHMMYY". How do I read the date+time on the system and pass it as parameter? I need also the -s as previous day and the -e as current day. Thanks, itik (1 Reply)
Discussion started by: itik
1 Replies
Login or Register to Ask a Question