Reputation: 11
20110216_00
20110216_01
...
20110216_23
20110217_00
..
and so on
I have tried with
date +'%Y%m%d_%H'
but it never starts with 00-23 format but from 01-24 like format, hence I get hour part always incorrect.
Can anybody suggest, how can I get above o/p
Upvotes: 1
Views: 24368
Reputation: 414
What revision of Solaris are you using? It is roughly 22:30 locally and I see:
mph@sol11express:~$ date +'%Y%m%d_%H' 20110216_22 mph@sol11express:~$ uname -a SunOS sol11express 5.11 snv_151a i86pc i386 i86pc Solaris mph@sol11express:~$ echo $SHELL /bin/bash
which looks to me like it is using 0-23 for hours.
Upvotes: 0
Reputation: 581
I tried it on SunOS 5.10 This works !
date +%Y%m%d_%H
-> 20130912_02
date +'%Y%m%d_%H'
-> 20130912_02
Can you tell us which Solaris are you using ?
uname -a
Cheers !
Upvotes: 0
Reputation: 21921
You can do it by manupulating the hour part. Check the snip below.
#/bin/ksh
s=`date +'%Y%m%d_'`
t=` date +'%H'`
let t=$t+1
echo "Required date is " $s$t
It gives
Required date is 20110316_16
Upvotes: 0