unix - How to use ubuntu command line to find a holiday? -


how use ubuntu command find date of mother's day (second sunday of may) in 2017?

since -v doesn't work on ubuntu, works on mac.

lets second sunday of may :

fhenri@machine:~$ date -v1d -v5m -v+1y -v+2w -v-sun dim 14 mai 2017 22:56:28 cest 

you should @ man date more examples , find out if need particular sunday or fix day

i running on macos (freebsd based) , did not realized date not uniform across *nix system.

on ubuntu, revealed bit more difficult here how go

vagrant@ubuntu:~$ firstofmay=$(date -d '05/01/2017') vagrant@ubuntu:~$ firstsunday=$(date -d "$firstofmay" '+%y-%m')-$(( 8 - $(date -d "$firstofmay" '+%u') )) vagrant@ubuntu:~$ secondsunday=$(date -d "$firstsunday + 1 week" '+%y-%m-%d') vagrant@ubuntu:~$ echo $secondsunday 2017-05-14 
  1. first initialize 1st of may base date
  2. then format of first sunday month: day 7 based , $(date -d "$firstofmonth" '+%u') day number of first of may (i.e.: monday 1); gives format such yyyy-mm-dd
  3. adding 1 week date have gives correct date - adjust formatting if want different

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -