Database Reference
In-Depth Information
Figure 11.3
Selecting the current date and time.
Figure 11.3 shows the way that CURRENT_TIME is output in a query. You can insert the
current time into a table using a similar technique to that which we demonstrated with the
NOW() function.
YEAR
YEAR() allows you to extract the year from a given date. You need to pass a date to the
YEAR function as follows:
YEAR(aDate)
aDate is any object that contains a date part. So we could use the following to output the
current year in a select statement:
SELECT
YEAR( NOW() )
AS This_year_is
Figure 11.4 shows this query along with the next function. We have passed NOW() in as
the date, which will actually pass in the date and time, but the YEAR() function ignores the
extra data and works with just the date portion of the NOW() output.
MONTH
MONTH() works in the same way as YEAR() but outputs the numerical value correspon-
ding to the month of the date given. The function takes the following format:
MONTH(aDate)
aDate is any object that contains a date part. So we could use the following to output the
current month number in a select statement:
SELECT
MONTH( NOW() )
AS The_month_is
Search WWH ::




Custom Search