Database Reference
In-Depth Information
Figure 11.4
Selecting the current year and month.
As previously, we have combined this query with the results from the YEAR function
which are shown in Figure 11.4.
MONTHNAME
Using MONTH() to find the month number as shown above is fine if you are wanting to
perform some month calculations, but if we are presenting this to the user we may wish to
output the month name in words. We do this by using the MONTHNAME() function, which
takes the following format:
MONTHNAME(aDate)
As usual, aDate is any object that contains a valid date. We will demonstrate this by a dif-
ferent query this time. The following query will show the months of all the entries in the log
table:
SELECT MONTHNAME(datecreated)
FROM
Log
Figure 11.5 shows our log table with the month, as opposed to the exact date and time,
that each entry was created. Notice how on this occasion we inserted the current row's
DateCreated field into the function as the date. The query has processed the function for
each row in the table. Depending on how closely you have followed the INSERT statements
in this topic, your table may have more or fewer rows.
DAYNAME
DAYNAME() will return the day that a given date falls on. You need to pass the function a
date as follows:
SELECT
DAYNAME( NOW() )
Figure 11.6 shows the results when combined with the next two examples. You will see
from the figure that I am writing this on 23 December 2002, which is a Monday.
Search WWH ::




Custom Search