linux-admin.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Special date/cal needs eg. "thrid friday of july"
@ 2007-01-11 15:23 Martin Klier
  2007-01-11 16:56 ` Kirkwood, David A.
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Martin Klier @ 2007-01-11 15:23 UTC (permalink / raw)
  To: linux-admin

[-- Attachment #1: Type: text/plain, Size: 804 bytes --]

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,
-- 
Mit freundlichen Grüßen

i.A. Martin Klier
Systemadministration / Datenbanken
-----------------------------------------------------------------
A.T.U Auto-Teile-Unger
Handels GmbH & Co. KG

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Special date/cal needs eg. "thrid friday of july"
  2007-01-11 15:23 Special date/cal needs eg. "thrid friday of july" Martin Klier
@ 2007-01-11 16:56 ` Kirkwood, David A.
  2007-01-11 17:47 ` Benoît Rouits
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Kirkwood, David A. @ 2007-01-11 16:56 UTC (permalink / raw)
  To: Martin Klier, linux-admin

This method may be out of date, but if you add the CPAN for Date::Calc to a perl script you can write a script that will manipulate a given date to add / subtract dates and give days of the week, months etc as output or viseversa

David 

-----Original Message-----
From: linux-admin-owner@vger.kernel.org [mailto:linux-admin-owner@vger.kernel.org] On Behalf Of Martin Klier
Sent: Thursday, January 11, 2007 10:24 AM
To: linux-admin@vger.kernel.org
Subject: Special date/cal needs eg. "thrid friday of july"

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,
-- 
Mit freundlichen Grüßen

i.A. Martin Klier
Systemadministration / Datenbanken
-----------------------------------------------------------------
A.T.U Auto-Teile-Unger
Handels GmbH & Co. KG
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Special date/cal needs eg. "thrid friday of july"
  2007-01-11 15:23 Special date/cal needs eg. "thrid friday of july" Martin Klier
  2007-01-11 16:56 ` Kirkwood, David A.
@ 2007-01-11 17:47 ` Benoît Rouits
  2007-01-11 20:26 ` Doug Knight
  2007-01-12 15:02 ` Adam T. Bowen
  3 siblings, 0 replies; 5+ messages in thread
From: Benoît Rouits @ 2007-01-11 17:47 UTC (permalink / raw)
  To: Martin Klier; +Cc: linux-admin

Hi

An example relative to this week:
ben@chimay:~ $ date -d "tuesday + 34 weeks"
[will give the next tuesday 34 weeks in the future]

An example relative to now
ben@chimay:~ $ date -d "now + 35 seconds - 3 days + 1 year"
[will give a dummy date in year 2008, based on "now" and some + and - ]

Other example
ben@chimay:~ $ date -d "3 days ago"
[no comment]

An absolute date:
ben@chimay:~ $ date -d "2007 1 jan"

could not find out how to mix absolute dates and '+' and '-'
HTH

Le jeudi 11 janvier 2007 à 16:23 +0100, Martin Klier a écrit :
> 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@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Special date/cal needs eg. "thrid friday of july"
  2007-01-11 15:23 Special date/cal needs eg. "thrid friday of july" Martin Klier
  2007-01-11 16:56 ` Kirkwood, David A.
  2007-01-11 17:47 ` Benoît Rouits
@ 2007-01-11 20:26 ` Doug Knight
  2007-01-12 15:02 ` Adam T. Bowen
  3 siblings, 0 replies; 5+ messages in thread
From: Doug Knight @ 2007-01-11 20:26 UTC (permalink / raw)
  To: Martin Klier; +Cc: linux-admin

Martin,

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)

#!/bin/sh

# Parse input
week=$1
weekday=$2
month=$4
case "$week" in
  [Ff][Ii][Rr][Ss][Tt])
    skip_weeks=0;
    ;;
  [Ss][Ee][Cc][Oo][Nn][Dd])
    skip_weeks=1;
    ;;
  [Tt][Hh][Ii][Rr][Dd])
    skip_weeks=2;
    ;;
  [Ff][Oo][Uu][Rr][Tt][Hh])
    skip_weeks=3;
    ;;
  [Ff][Ii][Ff][Tt][Hh])
    skip_weeks=4;
    ;;
esac

# 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,

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Special date/cal needs eg. "thrid friday of july"
  2007-01-11 15:23 Special date/cal needs eg. "thrid friday of july" Martin Klier
                   ` (2 preceding siblings ...)
  2007-01-11 20:26 ` Doug Knight
@ 2007-01-12 15:02 ` Adam T. Bowen
  3 siblings, 0 replies; 5+ messages in thread
From: Adam T. Bowen @ 2007-01-12 15:02 UTC (permalink / raw)
  To: Martin Klier; +Cc: linux-admin

Hi,

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,

I love the --date GNU extension, but I tried a number of different
syntaxes to get it to do what you wanted without any luck.  So I thought
a one line pipe would be fun:

cal 7 2007 | awk -F. 'NR > 2{print substr($1,5*3+1,2)}' | grep '[0-9]' |
awk 'NR == 3 {print $1}'

You set the day you're interested in through the first integer of the
second parameter of the substr call of the awk command.  0=Sunday
(0*3+1), 1=Monday (1*3+1) etc.  You set the week number with the 'NR ==
n' part of the final awk.  You set the month and year with the
parameters to cal.  It invokes awk twice which if used in a very tight
loop could be a problem.  It would be easy to merge the awk | grep | awk
into one awk command, but it starts to look more like program code on a
single line rather than a series of simple(-ish) commands.

Cheers

Adam

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-01-12 15:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-11 15:23 Special date/cal needs eg. "thrid friday of july" Martin Klier
2007-01-11 16:56 ` Kirkwood, David A.
2007-01-11 17:47 ` Benoît Rouits
2007-01-11 20:26 ` Doug Knight
2007-01-12 15:02 ` Adam T. Bowen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).