Extracting weekday name and month name from a date


Occasionally, there is a need to extract names (weekday name, month name) rather than numbers from a date field. This is useful for generating more readable lists or tables.


EXAMPLE DATABASE: World

DATA INPUT

Table politics in the database World.mdb is used as input.



QUERY date_names

SELECT country, independence, 
       WEEKDAYNAME(WEEKDAY(independence)) AS weekday,
       MONTHNAME(MONTH(independence)) AS month, 
       government
FROM politics
WHERE independence IS NOT NULL;

Query date_names produces the output below which shows two additional columns containing the name of the weekday and the name of the month.



DISCUSSION

The queries above show how the names of date elements (weekday name, month name) can be extracted from a date-type field. The weekday and the month are first extracted as numbers, which are in turn converted to names with the special functions WeekdayName( ) and MonthName( ).

  • WeekdayName(1) is Sunday, and WeekdayName(7) is Saturday.
  • MonthName(1) is January, and MonthName(12) is December.


Last modified September 23, 2008 3:19 am