an hour less in 24 hour system


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers an hour less in 24 hour system
# 1  
Old 10-23-2006
Data an hour less in 24 hour system

My program:

__________________________________

#!/bin/ksh

DAY=`date +%y%m%d`
H=`date +%H`
M=`date +%M`
day=`date +%m/%d/%y`
let h=$H-1
echo DAY $DAY
echo H $H
echo M $M
echo day $day
echo h $h

_____________________________________

My result:

______________________________________

DAY 061023
H 09
M 38
day 10/23/06
h 8

_______________________________________


My need help:


on the "let h=$H-1" I have the result of number 8; how can I make it 08 ( have the zero in front of 8)


please help
# 2  
Old 10-23-2006
use typeset

Just declare 'h' using
Code:
typeset -Z2 h

And then do your calculations. Also check this post for more details - typeset
# 3  
Old 10-23-2006
Code:
printf "%02d" $h

# 4  
Old 10-23-2006
just for inf purpose only

if [ $h -lt 10 ]
then
h=0$h
fi
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Want to get average value for each hour

I want to get CPU average value only (not required user CPU & memory) with each hours on individual date. The sample output is below | | | User |Memory| User | Date | Time |CPU %|CPU % | % |Mem % | 03/02/2015|00:00:00| 24.56| 20.66| 89.75| 63.48|... (13 Replies)
Discussion started by: Saravanan_0074
13 Replies

2. Shell Programming and Scripting

How to get next hour?

Hi guys I want any script to get me next hour For example Nexthour.sh 2013022823 It get me result 2013030100 Thanks a lot , I'm using Solaris 10 (5 Replies)
Discussion started by: teefa
5 Replies

3. Shell Programming and Scripting

How to convert 24 hour time to 12 hour timing?

Hi friends, I want to convert 24 hour timing to 12 hour please help me... my data file looks like this.. 13-Nov-2011 13:27:36 15.32044 72.68502 13-Nov-2011 12:08:31 15.31291 72.69807 16-Nov-2011 01:16:54 15.30844 72.74028 15-Nov-2011 20:09:25 15.35096 ... (13 Replies)
Discussion started by: nex_asp
13 Replies

4. Shell Programming and Scripting

Getting the last hour from a log.

I have a log like this: Jan 26 13:59:41 server2 ntpdate: step time server 91.189.94.4 offset 0.065456 sec Jan 26 13:59:41 server2 ntpd: ntpd 4.2.4p8@1.1612-o Fri Aug 6 22:49:54 UTC 2010 (1) Jan 26 13:59:41 server2 ntpd: precision = 1.000 usec Jan 26 13:59:41 server2 ntpd: ntp_io: estimated max... (2 Replies)
Discussion started by: Jotne
2 Replies

5. What is on Your Mind?

Power Hour?

I had some free time at work today so I decided to get a little practice with my shell scripts (I'm pretty new to the whole UNIX thing). I'm sure I'm not the only college student here so maybe this code will come in handy for future weekends. #!/bin/sh if then echo "No playlist... (0 Replies)
Discussion started by: thedoobieman5
0 Replies

6. Linux

my server is 1 hour behind after DST

Hello, I have linux server which is one hour behind after the DST change last week. I post some information below on the settings. any helpwould be helpful since I am newbie.. $ clock Tue 04 Nov 2008 03:12:26 PM EST -0.785549 seconds $more clock Tue 04 Nov 2008 03:12:26 PM EST... (2 Replies)
Discussion started by: jbdavis02@yahoo
2 Replies

7. Shell Programming and Scripting

help in hour grep

i have this script that checks for yesterday date and also specific hour in that ----------------------------------------------------------------- TZ=`date +%Z`+24 ;a=`date +%Y-%m-%d %k` cd logs count=0 for i in DBMaint.log do cat $i | grep $a >> file12.txt done... (0 Replies)
Discussion started by: ali560045
0 Replies

8. AIX

AIX 5.3 12 Hour System Clock

Hello Everyone, I have a Domino application running on AIX 5.3 that does time conversions worldwide. It uses the operating system time as a reference for the conversion. My problem is that I need the AIX OS clock to be a 12 hour clock (AM/PM) rather than a 24 hour clock. I have tried the date... (2 Replies)
Discussion started by: RTwitchell
2 Replies

9. UNIX for Dummies Questions & Answers

1 Hour less

set DAY=`date +%y%m%d` set H=`date +%H` set M=`date +%M` mailx -s "$H-Mydata" myemail@mail.com<mydata I am looking to set the current hour to have 1 hour less in the subject header: For example: let's say the system time is 8 I want to have "7-Mydata" not "8-Mydata" Can some1... (6 Replies)
Discussion started by: bobo
6 Replies

10. Shell Programming and Scripting

record wc -l over 24 hour period

I need to keep track of this output echo "dis chs(*)" | runmqsc | grep RUNNING | wc -l I need to record that count once an hour 24 hours a day and write to a file with the date and time it was run. Any idea on how to do this. (5 Replies)
Discussion started by: csaunders
5 Replies
Login or Register to Ask a Question