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

--nextPart1911097.vUrFitDRvP
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

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,
=2D-
Mit freundlichen Gr=C3=BC=C3=9Fen

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

--nextPart1911097.vUrFitDRvP
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQBFplaSVKZfihvnEcQRAvZSAKCBhrcgy1J7jVTvQdLnnzpCjnR7AgCd EUfL
LFuta033/UXheIkpOeDQMKY=
=MC77
-----END PGP SIGNATURE-----

--nextPart1911097.vUrFitDRvP--
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Martin Klier [ Do, 11 Januar 2007 16:23 ] [ ID #1591616 ]

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

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 da=
te to add / subtract dates and give days of the week, months etc as out=
put or viseversa

David

-----Original Message-----
=46rom: linux-admin-owner [at] vger.kernel.org [mailto:linux-admin-owner [at] vge=
r.kernel.org] On Behalf Of Martin Klier
Sent: Thursday, January 11, 2007 10:24 AM
To: linux-admin [at] 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 "sec=
ond
wednesday each month"? I crossread the manuals for date and gcal, but i=
t
seems to be impossible. Next thing I found was gcal, with
"--period-of-fixed-dates", but I have not been able to get useful resul=
ts,
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 [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
DAVID.A.KIRKWOOD [ Do, 11 Januar 2007 17:56 ] [ ID #1591617 ]

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

Hi

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

An example relative to now
ben [at] 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 [at] chimay:~ $ date -d "3 days ago"
[no comment]

An absolute date:
ben [at] chimay:~ $ date -d "2007 1 jan"

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

Le jeudi 11 janvier 2007 =C3=A0 16:23 +0100, Martin Klier a =C3=A9crit =
:
> Hi Linux Admins,
>
> is there a command to get something like "thrid friday of july" or "s=
econd
> 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 res=
ults,
> and
> date -d "35 tuesday" (35th tuesday of a year), but I have not been ab=
le 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 whe=
re 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 [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
brouits [ Do, 11 Januar 2007 18:47 ] [ ID #1591618 ]

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

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,
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Doug Knight [ Do, 11 Januar 2007 21:26 ] [ ID #1591619 ]

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

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
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
adam.bowen [ Fr, 12 Januar 2007 16:02 ] [ ID #1592896 ]
Linux » gmane.linux.admin » Special date/cal needs eg. "thrid friday of july"

Vorheriges Thema: !! Error in fstab !!
Nächstes Thema: secure file