Difference between revisions of "YEAR"

From SQLZOO
Jump to: navigation, search
 
(One intermediate revision by one user not shown)
Line 5: Line 5:
 
<tr><td align='left'>ingres</td><td>Yes</td><td>[[EXTRACT |EXTRACT(YEAR from d)]]</td></tr>
 
<tr><td align='left'>ingres</td><td>Yes</td><td>[[EXTRACT |EXTRACT(YEAR from d)]]</td></tr>
 
<tr><td align='left'>mysql</td><td>Yes</td><td>[[EXTRACT |EXTRACT(YEAR from d)]]</td></tr>
 
<tr><td align='left'>mysql</td><td>Yes</td><td>[[EXTRACT |EXTRACT(YEAR from d)]]</td></tr>
<tr><td align='left'>oracle</td><td>No</td><td>[[TO_CHAR(d,'YYYY')]]</td></tr>
+
<tr><td align='left'>oracle</td><td>No</td><td>[[TO_CHAR(dates) |TO_CHAR(d,'YYYY')]]</td></tr>
 
<tr><td align='left'>postgres</td><td>No</td><td>[[EXTRACT |EXTRACT(YEAR from d)]]</td></tr>
 
<tr><td align='left'>postgres</td><td>No</td><td>[[EXTRACT |EXTRACT(YEAR from d)]]</td></tr>
 
<tr><td align='left'>sqlserver</td><td>Yes</td><td>[[DATEPART |DATEPART(YEAR,d)]]</td></tr>
 
<tr><td align='left'>sqlserver</td><td>Yes</td><td>[[DATEPART |DATEPART(YEAR,d)]]</td></tr>
Line 39: Line 39:
 
<ul>
 
<ul>
 
   <li>[[EXTRACT |EXTRACT function]]</li>
 
   <li>[[EXTRACT |EXTRACT function]]</li>
   <li>[[ +(date) function]]</li>
+
   <li>[[%2B(dates) |+(date) function]]</li>
 
   <li>[[HOUR |HOUR function]]</li>
 
   <li>[[HOUR |HOUR function]]</li>
 
   <li>[[MINUTE |MINUTE function]]</li>
 
   <li>[[MINUTE |MINUTE function]]</li>
 
   <li>[[DAY |DAY function]]</li>
 
   <li>[[DAY |DAY function]]</li>
   <li>[[SECOND function]]</li>
+
   <li>[[SECOND |SECOND function]]</li>
 
   <li>[[MONTH |MONTH function]]</li>
 
   <li>[[MONTH |MONTH function]]</li>
 
</ul>
 
</ul>
 +
 +
{{Languages}}

Latest revision as of 21:38, 21 October 2012

Compatibility
YEAR(d)
EngineOKAlternative
ingresYesEXTRACT(YEAR from d)
mysqlYesEXTRACT(YEAR from d)
oracleNoTO_CHAR(d,'YYYY')
postgresNoEXTRACT(YEAR from d)
sqlserverYesDATEPART(YEAR,d)

YEAR

YEAR allows you to retrieve the year from a date.

   YEAR(d)

In this example you get the year from the date field whn.

SELECT EXTRACT(YEAR FROM whn) AS v
      ,whn
      ,wht
  FROM eclipse
SELECT TO_CHAR(whn,'YEAR') AS v
      ,whn
      ,wht
  FROM gisq.eclipse
SELECT YEAR(whn) AS v, whn, wht
  FROM eclipse

See also

Language: English  • Deutsch
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense