How to create a date range for random data in bash

I need to generate rows with all days of the year

Example:

MIN_DATE=01.01.2012 MAX_DATE=31.12.2012 for date in {1...366..1} do echo ... done 
+7
source share
3 answers
 for d in {0..365}; do date -d "2012-01-01 + $d days" +'%d.%m.%Y'; done 
+11
source

Not a clean bash solution, but my dateutils might help:

 dseq 01.01.2012 31.12.2012 -f %d.%m.%Y -i %d.%m.%Y => 01.01.2012 02.01.2012 ... 31.12.2012 

The output format can be configured with -f and the input format with -i .

+2
source

Using the ISO 8601 date format (year-month-day), you can compare dates lexicographically. This is a bit messier than we would like, since bash does not have a "<=" operator for strings.

 year=2011 d="$year-01-01" last="$(($year+1))-01-01" while [[ $d < $last ]]; do echo $d d=$(date +%F --date "$d + 1 day") done 
0
source

All Articles