getting hour minus the current time | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

getting hour minus the current time

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-21-2008
shehzad_m shehzad_m is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 18 July 2011, 4:36 PM EDT
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
getting hour minus the current time

Can some one help me getting last hour of the current time with date command in a script.
Sponsored Links
    #2  
Old 08-21-2008
sudhamacs sudhamacs is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 29 April 2010, 11:34 AM EDT
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
date +%H -d "1 hour ago"
Sponsored Links
    #3  
Old 08-22-2008
shehzad_m shehzad_m is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 18 July 2011, 4:36 PM EDT
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by sudhamacs View Post
date +%H -d "1 hour ago"
Just giving me 08...i want it like if its 8:00 i want to show 7:00 but i want it in an YYYYMMDDHH format.
    #4  
Old 08-22-2008
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 29 October 2014, 5:00 PM EDT
Location: The Netherlands
Posts: 7,719
Thanks: 123
Thanked 538 Times in 508 Posts

Code:
date "+%Y%m%d%H" -d "1 hour ago"

Regards
Sponsored Links
    #5  
Old 08-22-2008
sudhamacs sudhamacs is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 29 April 2010, 11:34 AM EDT
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Try this :
TZ=GMT+x date +%Y%m%d%H
where x is the time u r behind(+) or ahead(-) of GMT + 1
Sponsored Links
    #6  
Old 08-22-2008
shehzad_m shehzad_m is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 18 July 2011, 4:36 PM EDT
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by sudhamacs View Post
Try this :
TZ=GMT+x date +%Y%m%d%H
where x is the time u r behind(+) or ahead(-) of GMT + 1
one final question..how can should this in a shell script if i wanna use TZ?
Sponsored Links
    #7  
Old 08-22-2008
sudhamacs sudhamacs is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 29 April 2010, 11:34 AM EDT
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by shehzad_m View Post
one final question..how can should this in a shell script if i wanna use TZ?
var=`TZ=GMT+5 date +%Y%m%d%H`
Sponsored Links
Closed Thread

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
crontab 1 hour off from current time homeyjoe AIX 2 03-09-2012 09:58 AM
How to show time minus 60 minutes? s ladd Solaris 5 12-01-2011 11:06 AM
sqlite: calculating with dates - compare current date minus 6 months with stored record slashdotweenie UNIX and Linux Applications 0 03-10-2011 08:23 AM
Compare file timestamp with current date. Diff must be 1 hour. taipan Shell Programming and Scripting 3 12-28-2009 02:40 AM
Get date and time for past 1 hour from current date spch2o Shell Programming and Scripting 5 08-29-2008 04:32 AM



All times are GMT -4. The time now is 12:41 PM.