October 18th, 2012, 03:25 PM
Generating random dates then add x days to that date
I have made a bash script to generate random dates using /bin/date
The dates are output to the console.
Now I want to take those dates and add x number of days to them ie. 5 days.
So an example output would be:
while [ $1 -lt 10 ]
d=$(date -d "$((RANDOM%1+2012))-$((RANDOM%12+1))-$((RANDOM%28+1))" '+%d-%m-%Y')
i=$(( $i + 1 ))
October 18th, 2012, 06:30 PM
You can use one of the options of the attached script to perform lots of date functions(date arithmetic, conversions, etc).
October 23rd, 2012, 01:08 AM
Thanks for the information it is a very good post now I know about this X-post.
October 23rd, 2012, 02:26 PM
It was late and I had to look at the code with fresh eyes. Next morning I took the existing code and manipulated it in a very simple manor.
Originally Posted by spacebar208
Since $d generates a random date in 2012 using /bin/date and random.
and since date takes the parameter 'days' or 'days ago'. All I needed to do was pass $d to date with days set to 10. This would generate a random date and a date that was 10 days in the future from that previous date.