4 This is moved to the accepted answer edited Sep 1 '11 at 13:51 Johan 3,38911 gold badge1919 silver badges3030 bronze badges How can I use the date command to convert something like "monday week 40" into a ISO date? I am playing with something like this: ``````date --date='monday week 40' +'%Y-%m-%d' `````` And the date I'm searching for would be 2011-10-03. But my problem is that this date string is not valid, so I need another approach to solve this problem. /Thanks Answer: A working solution based on manatwork:s answer. This will return the correct date. ``````date -d "\$(date -d "\$(date +'%Y-01-01') +40 weeks" +"%F") -\$(date -d "\$(date +'%Y-01-01') +40 weeks" +%w) days +1 day" +"%F" `````` There is 3 date commands here. ``````\$>date +'%Y-01-01' 2011-01-01 \$>date -d "\$(date +'%Y-01-01') +40 weeks" +"%F" 2011-10-08 \$>date -d "\$(date +'%Y-01-01') +40 weeks" +"%w" 6 `````` And that would become ``````\$>date -d "2011-10-08 -6 days +1 day" +"%F" 2011-10-03 `````` More or less, start with the first day of the week and jump forward 40 weeks, and subtract the week day number to get to a Sunday (since date command starts with Sundays and not Mondays) and add the one to go to the Monday. How can I use the date command to convert something like "monday week 40" into a ISO date? I am playing with something like this: ``````date --date='monday week 40' +'%Y-%m-%d' `````` And the date I'm searching for would be 2011-10-03. But my problem is that this date string is not valid, so I need another approach to solve this problem. /Thanks Answer: A working solution based on manatwork:s answer. This will return the correct date. ``````date -d "\$(date -d "\$(date +'%Y-01-01') +40 weeks" +"%F") -\$(date -d "\$(date +'%Y-01-01') +40 weeks" +%w) days +1 day" +"%F" `````` There is 3 date commands here. ``````\$>date +'%Y-01-01' 2011-01-01 \$>date -d "\$(date +'%Y-01-01') +40 weeks" +"%F" 2011-10-08 \$>date -d "\$(date +'%Y-01-01') +40 weeks" +"%w" 6 `````` And that would become ``````\$>date -d "2011-10-08 -6 days +1 day" +"%F" 2011-10-03 `````` More or less, start with the first day of the week and jump forward 40 weeks, and subtract the week day number to get to a Sunday (since date command starts with Sundays and not Mondays) and add the one to go to the Monday. How can I use the date command to convert something like "monday week 40" into a ISO date? I am playing with something like this: ``````date --date='monday week 40' +'%Y-%m-%d' `````` And the date I'm searching for would be 2011-10-03. But my problem is that this date string is not valid, so I need another approach to solve this problem. /Thanks 3 clarified the question. edited Sep 1 '11 at 13:16 Johan 3,38911 gold badge1919 silver badges3030 bronze badges How can I use the date command to convert something like "monday week 40" into a ISO date? I am playing with something like this: ``````date --date='monday week 40' +'%Y-%m-%d' `````` And the date I'm searching for would be 2011-10-03. But my problem is that this date string is not valid, so I need another approach to solve this problem. /Thanks Answer: A working solution based on manatwork:s answer. This will return the correct date. ``````date -d "\$(date -d "\$(date +'%Y-01-01') +40 weeks" +"%F") -\$(date -d "\$(date +'%Y-01-01') +40 weeks" +%w) days +1 day" +"%F" `````` There is 3 date commands here. ``````\$>date +'%Y-01-01' 2011-01-01 \$>date -d "\$(date +'%Y-01-01') +40 weeks" +"%F" 2011-10-08 \$>date -d "\$(date +'%Y-01-01') +40 weeks" +"%w" 6 `````` And that would become ``````\$>date -d "2011-10-08 -6 days +1 day" +"%F" 2011-10-03 `````` More or less, start with the first day of the week and jump forward 40 weeks, and subtract the week day number to get to a Sunday (since date command starts with Sundays and not Mondays) and add the one to go to the Monday. How can I use the date command to convert something like "monday week 40" into a ISO date? I am playing with something like this: ``````date --date='monday week 40' +'%Y-%m-%d' `````` And the date I'm searching for would be 2011-10-03. But my problem is that this date string is not valid, so I need another approach to solve this problem. /Thanks This will return the correct date. ``````date -d "\$(date -d "\$(date +'%Y-01-01') +40 weeks" +"%F") -\$(date -d "\$(date +'%Y-01-01') +40 weeks" +%w) days +1 day" +"%F" `````` There is 3 date commands here. ``````\$>date +'%Y-01-01' 2011-01-01 \$>date -d "\$(date +'%Y-01-01') +40 weeks" +"%F" 2011-10-08 \$>date -d "\$(date +'%Y-01-01') +40 weeks" +"%w" 6 `````` And that would become ``````\$>date -d "2011-10-08 -6 days +1 day" +"%F" 2011-10-03 `````` More or less, start with the first day of the week and jump forward 40 weeks, and subtract the week day number to get to a Sunday (since date command starts with Sundays and not Mondays) and add the one to go to the Monday. How can I use the date command to convert something like "monday week 40" into a ISO date? I am playing with something like this: ``````date --date='monday week 40' +'%Y-%m-%d' `````` And the date I'm searching for would be 2011-10-03. But my problem is that this date string is not valid, so I need another approach to solve this problem. /Thanks Answer: A working solution based on manatwork:s answer. This will return the correct date. ``````date -d "\$(date -d "\$(date +'%Y-01-01') +40 weeks" +"%F") -\$(date -d "\$(date +'%Y-01-01') +40 weeks" +%w) days +1 day" +"%F" `````` There is 3 date commands here. ``````\$>date +'%Y-01-01' 2011-01-01 \$>date -d "\$(date +'%Y-01-01') +40 weeks" +"%F" 2011-10-08 \$>date -d "\$(date +'%Y-01-01') +40 weeks" +"%w" 6 `````` And that would become ``````\$>date -d "2011-10-08 -6 days +1 day" +"%F" 2011-10-03 `````` More or less, start with the first day of the week and jump forward 40 weeks, and subtract the week day number to get to a Sunday (since date command starts with Sundays and not Mondays) and add the one to go to the Monday. Tweeted twitter.com/#!/StackUnix/status/109244371701993472 occurred Sep 1 '11 at 12:41 2 a working example. edited Sep 1 '11 at 11:26 Johan 3,38911 gold badge1919 silver badges3030 bronze badges How can I use the date command to convert something like "monday week 40" into a ISO date? I am playing with something like this: ``````date --date='monday week 40' +'%Y-%m-%d' `````` And the date I'm searching for would be 2011-10-03. But my problem is that this date string is not valid, so I need another approach to solve this problem. /Thanks This will return the correct date. ``````date -d "\$(date -d "\$(date +'%Y-01-01') +40 weeks" +"%F") -\$(date -d "\$(date +'%Y-01-01') +40 weeks" +%w) days +1 day" +"%F" `````` There is 3 date commands here. ``````\$>date +'%Y-01-01' 2011-01-01 \$>date -d "\$(date +'%Y-01-01') +40 weeks" +"%F" 2011-10-08 \$>date -d "\$(date +'%Y-01-01') +40 weeks" +"%w" 6 `````` And that would become ``````\$>date -d "2011-10-08 -6 days +1 day" +"%F" 2011-10-03 `````` More or less, start with the first day of the week and jump forward 40 weeks, and subtract the week day number to get to a Sunday (since date command starts with Sundays and not Mondays) and add the one to go to the Monday. How can I use the date command to convert something like "monday week 40" into a ISO date? I am playing with something like this: ``````date --date='monday week 40' +'%Y-%m-%d' `````` And the date I'm searching for would be 2011-10-03. But my problem is that this date string is not valid, so I need another approach to solve this problem. /Thanks How can I use the date command to convert something like "monday week 40" into a ISO date? I am playing with something like this: ``````date --date='monday week 40' +'%Y-%m-%d' `````` And the date I'm searching for would be 2011-10-03. But my problem is that this date string is not valid, so I need another approach to solve this problem. /Thanks This will return the correct date. ``````date -d "\$(date -d "\$(date +'%Y-01-01') +40 weeks" +"%F") -\$(date -d "\$(date +'%Y-01-01') +40 weeks" +%w) days +1 day" +"%F" `````` There is 3 date commands here. ``````\$>date +'%Y-01-01' 2011-01-01 \$>date -d "\$(date +'%Y-01-01') +40 weeks" +"%F" 2011-10-08 \$>date -d "\$(date +'%Y-01-01') +40 weeks" +"%w" 6 `````` And that would become ``````\$>date -d "2011-10-08 -6 days +1 day" +"%F" 2011-10-03 `````` More or less, start with the first day of the week and jump forward 40 weeks, and subtract the week day number to get to a Sunday (since date command starts with Sundays and not Mondays) and add the one to go to the Monday. 1 asked Sep 1 '11 at 9:31 Johan 3,38911 gold badge1919 silver badges3030 bronze badges