With ksh93
:
d1=$(printf '%(%s)T\n' "2000-01-01 01:00:00")
d2=$(printf '%(%s)T\n' "2013-01-01 00:00:00")
for ((d=d1;d<d2;d+=3600)); do
printf '%(%F %-H%M)T\n' "#$d"
done
With zsh
:
zmodload zsh/datetime
strftime -rs d1 '%Y%m%d%H%M' 201201010100
strftime -rs d2 '%Y%m%d%H%M' 201301010000
for ((d=d1;d<d2;d+=3600)) strftime '%F %-H%M' $d
With perl
:
perl -MPOSIX -le '
$d1=mktime 0,0,1,1,0,100;$d2=mktime 0,0,0,1,0,113;
for ($d=$d1; $d<$d2; $d+=3600) {
print strftime "%F %-H%M", localtime $d}'
With GNU awk
:
awk 'BEGIN {d1=mktime("2000 01 01 01 00 00")
d2=mktime("2013 01 01 00 00 00")
for (d=d1;d<d2;d+=3600)
print strftime("%F %-H%M",d)}'
Note that with all the above around DST changing time some hours will be skipped or output twice if in a timezone with DST as a clock would.
We're counting from 000 to 2300 instead of 100 to 2400.
echo "$(date +%F) 100 2000" >> somefile
Please explain your question so people could answer the question.2012-12-31 235959
is generally expressed as2013-01-01 000000
, not2012-12-31 240000
.