Friday, September 16, 2005

gnu date increment by 1

> Hi

> With gnu date, how can I get the list of dates continuosly between a
> specific period say for example apr 2,2005 to july 31,2005 in the
> format %Y/%m/%d

> command should be in the form of
> ./script -d1 04/02/2005 -d2 06/31/2005

ITYM 07/31/2005

> 2005/04/02
> 2005/04/03
> 2005/04/04
> ..
> ..
> ..
> 2005/07/29
> 2005/07/30/
> 2005/07/30

> Help is very much appreciated.

> Thanks,

Something like this should work:

now=`date +"%Y/%m/%d" -d "04/02/2005"`
end=`date +"%Y/%m/%d" -d "07/31/2005"`

while [ "$now" != "$end" ]
do
now=`date +"%Y/%m/%d" -d "$now + 1 day"`
echo "$now"
done

Note that date handles some invalid dates like "06/31/2005" by trying to
map them to a close real date.

Regards,

Ed.

0 Comments:

Post a Comment

<< Home