4 This is moved to the accepted answer
source | link

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.
source | link

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
2 a working example.
source | link

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
source | link