home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!ukma!hsdndev!dartvax!kip-sn-16.dartmouth.edu!user
- From: carl.pedersen@dartmouth.edu (L. Carl Pedersen)
- Newsgroups: comp.databases.theory
- Subject: Re: date -> day of week conversion
- Message-ID: <carl.pedersen-141292200412@kip-sn-16.dartmouth.edu>
- Date: 15 Dec 92 01:51:07 GMT
- References: <Byqssz.Bu5@gabriel.keele.ac.uk> <dtb.724154401@otto> <1992Dec14.174550.24045@enterprise.rdd.lmsc.lockheed.com>
- Sender: news@dartvax.dartmouth.edu (The News Manager)
- Followup-To: comp.databases.theory
- Organization: Dartmouth College
- Lines: 49
-
- In article <1992Dec14.174550.24045@enterprise.rdd.lmsc.lockheed.com>,
- stroup@aspen.ops.lmsc.lockheed.com () wrote:
- >
- >
- > >
- > csa09@keele.ac.uk (Paul Singleton) writes:
- >
- > >Can anyone produce SQL code to convert a date from DD/MM/YY (or MM/DD/YY)
- > >format into the corresponding day of the week? I assume that you can
- > >get at the individual DD, MM and YY fields (as integers?).
- >
- > >
- >
- > Maybe I'm missing the point here (or maybe this is an Oracle extension to
- > SQL) but can't you just use the to_char function:
- >
- > Select to_char(my_date,'DAY') from my_table;
- >
- > According to the doc, DAY gives you the name of the day, padded with blanks
- > to a length of nine characters.
- >
- > judie
-
- Yes. That is an ORACLE extension, obviously a good one. Does anyone know
- if the SQL92 standard provides something like this? It doesn't seem to be
- mentioned in the Melton/Simon book.
-
- I agree with whoever said this is not the sort of functionality SQL was
- designed for, but think it's still be possible to do the translation in a
- non-procedural way, depending on what functions are available in your local
- SQL dialect.
-
- In the gregorian calendar, the remainder of the year divided by 400
- determines whether or not it's a leap year. If you can extract the year,
- and determine the remainder mod 400, you could use that as an index into a
- table of year types (400 rows, values leap or normal).
-
- If you can extract the month, then the month combined with the year type
- can be used as a composite key into a table that tells how many days in the
- year preceded that month. (24 rows).
-
- Given all of the above, a complex expression can be written that converts a
- date to a number of days since the beginning of year zero. If you know
- what day of the week that was, you can use the result + the beginning day
- to look up in a little table of days.
-
- I make no claims that this is the best way to do this. I also do not claim
- that it takes into account any special cases, like historical changes to
- the calendar etc.
-