Show previous hour | 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.

Show previous hour

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 03-14-2011
pravin27 pravin27 is offline Forum Advisor  
Advisor
 
Join Date: Sep 2009
Last Activity: 17 April 2014, 8:15 AM EDT
Location: ./India/Mumbai
Posts: 1,201
Thanks: 55
Thanked 266 Times in 259 Posts
If you GNU date then use

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

Sponsored Links
    #3  
Old 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 03-14-2011
pravin27 pravin27 is offline Forum Advisor  
Advisor
 
Join Date: Sep 2009
Last Activity: 17 April 2014, 8:15 AM EDT
Location: ./India/Mumbai
Posts: 1,201
Thanks: 55
Thanked 266 Times in 259 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 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 03-14-2011
pravin27 pravin27 is offline Forum Advisor  
Advisor
 
Join Date: Sep 2009
Last Activity: 17 April 2014, 8:15 AM EDT
Location: ./India/Mumbai
Posts: 1,201
Thanks: 55
Thanked 266 Times in 259 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 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

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
Hour by Hour counting script. Where do I start? dahelgran Shell Programming and Scripting 4 07-12-2009 06:27 PM
new NIC card doesn't show in show-nets iperez Solaris 13 09-26-2008 04:52 AM
Secondary groups show in groups but don't show in id (Not working) zen03 HP-UX 4 12-31-2007 10:15 AM
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 01:35 PM.