I have rather basic task but wasn't able to find proper solution to it.
I want to iterate date interval since 2008 to current and need epoch values for each iteration of the loop. I am interested in iterating both years, halves and months as well.
I wrote such script
#!/bin/bash initial_date=`date -d "2008-02-04 00:00:00 UTC" +%s` end_date=`date +%s` n=0 until [ $initial_date -gt $end_date ]; do echo $initial_date let n+=1 readable_date=`date +"%Y-%m-%d %T" -d "1970-01-01 $initial_date sec"` echo $readable_date readable_date=`date -d "$readable_date + $n year"` initial_date=`date -d "$readable_date" +%s` done
but its output is rather weird to me:
Why the year is not incremented properly? Shifted hours seems to me a side-effect of unix>>UTC>>unix conversion. Is there any direct (without reconversion) method for doing this?
And yes, I checked this, this and this question and found no clear way of doing this. All they are based on incrementing number and converting date with the help of it which doesn't seem precise to me.
And yes, I thought about adding
60*60*24*30*365 to initial date but would it be correct? This approach doesn't consider leap years, months comprised of 31 days and so on.