Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Tuesday and Wednesday next week, with Linux date command

Tags:

linux

unix

At a Linux shell, you can do something like:

date -d "next Tuesday"

To get next Tuesday.

My issue is this: I want to get Tuesday of NEXT WEEK. So if I'm currently on Monday, I want it to go 7 days forward to next week, then evaluate "next Tuesday". Is there a way to chain the date evaluations somehow?

To further elaborate, if I am on a Wednesday, then next week's Tuesday is just 6 days away

like image 935
yi1 Avatar asked Feb 07 '23 22:02

yi1


1 Answers

date is cleverer than you'd think

~: date -d "next tuesday"
Tue Feb  2 00:00:00 GMT 2016
~: date -d "1 week next tuesday"
Tue Feb  9 00:00:00 GMT 2016
~: 

If you want to get the Tuesday of next week you can find the start of next week, then add a day

~: date -d "1 day next monday"
Tue Feb  2 00:00:00 GMT 2016

If you want it to be slightly clear you can use

~: date -d "next Monday + 1 day"
Tue Feb  2 00:00:00 GMT 2016

Based on Charles Duffy's comments it might be worth noting on my machine

~: date --version #on RHEL6
date (GNU coreutils) 8.4
<license stuff (GPLv3)>
like image 153
Holloway Avatar answered Mar 15 '23 17:03

Holloway