Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Show previous hour

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-14-2011
alvin0618 alvin0618 is offline
Registered User
 
Join Date: Mar 2011
Last Activity: 25 March 2011, 3:46 AM EDT
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Show previous hour


Code:
date +%Y%m%d%H

output :
2011031415

I want to get previous hour like this 2011031414. Any one can help ?
Sponsored Links
    #2  
Old Unix and Linux 03-14-2011
pravin27 pravin27 is offline Forum Advisor  
Advisor
 
Join Date: Sep 2009
Last Activity: 7 September 2016, 8:47 AM EDT
Location: ./India/Bangalore
Posts: 1,271
Thanks: 70
Thanked 299 Times in 290 Posts
If you GNU date then use

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

Sponsored Links
    #3  
Old Unix and Linux 03-14-2011
alvin0618 alvin0618 is offline
Registered User
 
Join Date: Mar 2011
Last Activity: 25 March 2011, 3:46 AM EDT
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by pravin27 View Post
If you GNU date then use
I am using SunOS LSMS 5.10 .
    #4  
Old Unix and Linux 03-14-2011
pravin27 pravin27 is offline Forum Advisor  
Advisor
 
Join Date: Sep 2009
Last Activity: 7 September 2016, 8:47 AM EDT
Location: ./India/Bangalore
Posts: 1,271
Thanks: 70
Thanked 299 Times in 290 Posts
How about this?

Code:
perl -e '@dttime=(localtime(time - 60*60))[2,3,4,5];printf "%4d%02d%02d%02d\n",$dttime[3]+1900,$dttime[2]+1,$dttime[1],$dttime[0];'

Sponsored Links
    #5  
Old Unix and Linux 03-14-2011
alvin0618 alvin0618 is offline
Registered User
 
Join Date: Mar 2011
Last Activity: 25 March 2011, 3:46 AM EDT
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by pravin27 View Post
How about this?

Code:
perl -e '@dttime=(localtime(time - 60*60))[2,3,4,5];printf "%4d%02d%02d%02d\n",$dttime[3]+1900,$dttime[2]+1,$dttime[1],$dttime[0];'

how you show me how to store this result into a variable $target_date ?
Sponsored Links
    #6  
Old Unix and Linux 03-14-2011
pravin27 pravin27 is offline Forum Advisor  
Advisor
 
Join Date: Sep 2009
Last Activity: 7 September 2016, 8:47 AM EDT
Location: ./India/Bangalore
Posts: 1,271
Thanks: 70
Thanked 299 Times in 290 Posts

Code:
##target_date=$(perl -e '@dttime=(localtime(time - 60*60))[2,3,4,5];printf "%4d%02d%02d%02d\n",$dttime[3]+1900,$dttime[2]+1,$dttime[1],$dttime[0];')
##echo $target_date
2011020219

Sponsored Links
    #7  
Old Unix and Linux 03-14-2011
alvin0618 alvin0618 is offline
Registered User
 
Join Date: Mar 2011
Last Activity: 25 March 2011, 3:46 AM EDT
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you. pravin27
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
an hour less in 24 hour system bobo UNIX for Dummies Questions & Answers 3 10-23-2006 11:55 AM
1 Hour less bobo UNIX for Dummies Questions & Answers 6 05-16-2006 12:07 PM



All times are GMT -4. The time now is 11:13 PM.