The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
calculate the date of next satureday of current date. rinku Shell Programming and Scripting 3 09-03-2008 12:05 AM
Using awk and current date command wereyou Shell Programming and Scripting 2 06-06-2008 08:25 PM
Perl: Extracting date from file name and comparing with current date MKNENI Shell Programming and Scripting 4 03-26-2008 04:01 PM
Processing a log file based on date/time input and the date/time on the log file primp Shell Programming and Scripting 4 03-16-2008 11:23 AM
File date vs Current date trexlim Shell Programming and Scripting 4 05-04-2007 10:35 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-20-2007
spch2o spch2o is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 2
Arrow Get date and time for past 1 hour from current date

Hi,

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

Thanks
  #2 (permalink)  
Old 12-21-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
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]'
20071220220154
  #3 (permalink)  
Old 12-21-2007
nhatch nhatch is offline
Registered User
  
 

Join Date: Aug 2002
Location: London, England
Posts: 85
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)


Code:
-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
-bash-3.00$

  #4 (permalink)  
Old 12-21-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,557
if you have GNU date

Code:
# date +%Y%m%d%H%M%S -d  "1 hour ago"
20071221193551

  #5 (permalink)  
Old 12-21-2007
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,441
FreeBSD

Code:
date -v -1H "+%Y-%m-%d %H:%M:%S"

  #6 (permalink)  
Old 08-29-2008
Georgie Georgie is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 1
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0