Re: Special date/cal needs eg. "thrid friday of july"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


This script should give you enough information to figure out how to do what
you want.  It is not intended to be used as written; it doesn't do any
syntax checking.

Throw the script in a file, mark it executable, and pass the date you're
looking, in the same format as third friday of july, on the command line.
(e.g. ./some_file third friday of july)


# Parse input
case "$week" in

# Convert the weekday to a number ( 1 = Monday, 2 = Tuesday, ... )
weekday_no=$( date -d "$weekday" +%u )

# Qualify the month with a year and a day (the first) for
# illustrative purposes
first_of_month=$( date -I -d "${month} 1" )

# Now that we're done formating the input, these three lines do the
# real work.

# Find the weekday number of the first day of the month
# (again 1 = Monday, ... )
first_weekday_no=$( date -d "${first_of_month} ${skip_weeks} weeks" +%u )

# Do some math; difference between desired weekdays + 7 then mod by 7.
let skip_days=(7+weekday_no-first_weekday_no)%7

# Use date to print the date.  You can format if desired.
date -d "${first_of_month} ${skip_weeks} weeks ${skip_days} days"

Doug Knight

Martin Klier wrote:
> Hi Linux Admins,
> is there a command to get something like "thrid friday of july" or "second 
> wednesday each month"? I crossread the manuals for date and gcal, but it 
> seems to be impossible. Next thing I found was gcal, with 
> "--period-of-fixed-dates", but I have not been able to get useful results, 
> and 
> date -d "35 tuesday" (35th tuesday of a year), but I have not been able to 
> limit it to months nor selecting the year (by the way, I do not need it).
> Has somebody experience with this one, and can you give me a hint where to 
> look, or even an example?
> Thanks a lot in advance,
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at

[Linux Newbie]     [Audio]     [Hams]     [Kernel Newbies]     [Util Linux NG]     [Security]     [Netfilter]     [Bugtraq]     [Photo]     [Yosemite Photos]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux Device Drivers]     [Samba]     [Video 4 Linux]     [Git]     [Linux Resources]     [Fedora Users]

Add to Google Powered by Linux