Difference between revisions of "MONTH"

From SQLZOO
Jump to: navigation, search
 
(2 intermediate revisions by one user not shown)
Line 3: Line 3:
 
<tr><th colspan='3'>MONTH(d)</th></tr>
 
<tr><th colspan='3'>MONTH(d)</th></tr>
 
<tr><td align='center'>'''Engine'''</td><td align='center'>'''OK'''</td><td align='center'>'''Alternative'''</td></tr>
 
<tr><td align='center'>'''Engine'''</td><td align='center'>'''OK'''</td><td align='center'>'''Alternative'''</td></tr>
<tr><td align='left'>ingres</td><td>Yes</td><td>[[EXTRACT |EXTRACT(HOUR from d)]]</td></tr>
+
<tr><td align='left'>ingres</td><td>Yes</td><td>[[EXTRACT |EXTRACT(MONTH from d)]]</td></tr>
<tr><td align='left'>mysql</td><td>Yes</td><td>[[EXTRACT |EXTRACT(HOUR from d)]]</td></tr>
+
<tr><td align='left'>mysql</td><td>Yes</td><td>[[EXTRACT |EXTRACT(MONTH from d)]]</td></tr>
<tr><td align='left'>oracle</td><td>No</td><td>[[TO_CHAR(dates) |TO_CHAR(d,'HH24')]]</td></tr>
+
<tr><td align='left'>oracle</td><td>No</td><td>[[TO_CHAR(dates) |TO_CHAR(d,'MM')]]</td></tr>
<tr><td align='left'>postgres</td><td>No</td><td>[[EXTRACT |EXTRACT(HOUR from d)]]</td></tr>
+
<tr><td align='left'>postgres</td><td>No</td><td>[[EXTRACT |EXTRACT(MONTH from d)]]</td></tr>
<tr><td align='left'>sqlserver</td><td>Yes</td><td>[[DATEPART |DATEPART(HOUR,d)]]</td></tr>
+
<tr><td align='left'>sqlserver</td><td>Yes</td><td>[[DATEPART |DATEPART(MONTH,d)]]</td></tr>
 
</table>
 
</table>
<h1>HOUR</h1>
+
<h1>MONTH</h1>
<p>HOUR allows you to retrieve the hour from a datetime.</p>
+
<p>MONTH allows you to retrieve the month from a date.</p>
 
<p></p>  
 
<p></p>  
 
<pre style='width:60ex'>
 
<pre style='width:60ex'>
   HOUR(d)
+
   MONTH(d)
 
</pre>
 
</pre>
  
 
<div class='ht'>
 
<div class='ht'>
In this example you get the hour from the datetime field whn.   
+
In this example you get the month from the date field whn.   
 
<source lang='sql' class='def e-postgres'>
 
<source lang='sql' class='def e-postgres'>
 
SELECT EXTRACT(MONTH from whn) AS v
 
SELECT EXTRACT(MONTH from whn) AS v

Latest revision as of 21:24, 21 October 2012

Compatibility
MONTH(d)
EngineOKAlternative
ingresYesEXTRACT(MONTH from d)
mysqlYesEXTRACT(MONTH from d)
oracleNoTO_CHAR(d,'MM')
postgresNoEXTRACT(MONTH from d)
sqlserverYesDATEPART(MONTH,d)

MONTH

MONTH allows you to retrieve the month from a date.

   MONTH(d)

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

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

See also

Language: English  • Deutsch
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense