Difference between revisions of "+ INTERVAL"

From SQLZOO
Jump to: navigation, search
 
(7 intermediate revisions by one user not shown)
Line 1: Line 1:
<h3>+ INTERVAL</h3>
+
<h1>+ INTERVAL</h1>
 
<table align='right' border='1'>
 
<table align='right' border='1'>
 
<caption>Compatibility</caption>
 
<caption>Compatibility</caption>
 
<tr><th colspan='3'>d+ INTERVAL i DAY</th></tr>
 
<tr><th colspan='3'>d+ INTERVAL i DAY</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'>mysql</td><td>Yes</td><td>[[d+ i]]</td></tr>
+
<tr><td align='left'>mysql</td><td>Yes</td><td>[[%2B(dates) |d+ i]]</td></tr>
<tr><td align='left'>oracle</td><td>No</td><td>[[d+ i]]</td></tr>
+
<tr><td align='left'>oracle</td><td>No</td><td>[[%2B(dates) |d+ i]]</td></tr>
<tr><td align='left'>postgres</td><td>No</td><td>[[d+ i]]</td></tr>
+
<tr><td align='left'>postgres</td><td>No</td><td>[[%2B(dates) |d+ i]]</td></tr>
<tr><td align='left'>sqlserver</td><td>No</td><td>[[d+ i]]</td></tr>
+
<tr><td align='left'>sqlserver</td><td>No</td><td>[[%2B(dates) |d+ i]]</td></tr>
 
</table>
 
</table>
 
<p><code><i>d</i> + INTERVAL <i>i</i> DAY</code>
 
<p><code><i>d</i> + INTERVAL <i>i</i> DAY</code>
Line 23: Line 23:
 
<div class=params>schema:gisq</div>
 
<div class=params>schema:gisq</div>
  
<div class='qu'>
+
<div class='ht'>
 
In this example we show the date 7 days after the value specified in <code>whn</code>  
 
In this example we show the date 7 days after the value specified in <code>whn</code>  
<source lang='sql' class='def'>
+
<source lang='sql' class='def e-oracle'>SELECT whn, (whn) + 7
SELECT whn, whn+INTERVAL 7 DAY
+
  FROM gisq.eclipse
 +
</source>
 +
<source lang='sql' class='def e-sqlserver'>SELECT whn, (whn) + 7  
 
   FROM eclipse
 
   FROM eclipse
 
</source>
 
</source>
 
+
<source lang='sql' class='def e-ingres'>SELECT whn, whn + DATE(7 day)
<source lang='sql' class='ans'>
+
  FROM eclipse
 +
</source>
 +
<source lang='sql' class='def e-postgres'>SELECT whn, whn + 7
 +
  FROM eclipse
 +
</source>
 +
<source lang='sql' class='def'>
 
SELECT whn, whn+INTERVAL 7 DAY
 
SELECT whn, whn+INTERVAL 7 DAY
 
   FROM eclipse
 
   FROM eclipse
Line 36: Line 43:
 
</div>
 
</div>
  
 +
<p>See also</p>
 
<ul>
 
<ul>
   <li>[[EXTRACT function]]</li>
+
   <li>[[EXTRACT |EXTRACT function]]</li>
 
</ul>
 
</ul>
 +
 +
{{Languages}}

Latest revision as of 09:09, 6 September 2012

+ INTERVAL

Compatibility
d+ INTERVAL i DAY
EngineOKAlternative
mysqlYesd+ i
oracleNod+ i
postgresNod+ i
sqlserverNod+ i

d + INTERVAL i DAY returns the date i days after the date d.

You can also add YEAR, MONTH, DAY, HOUR, MINUTE, SECOND

You can also add a negative value.

 DATE '2006-05-20' + INTERVAL 5 DAY   -> DATE '2006-05-25' 
 DATE '2006-05-20' + INTERVAL 5 MONTH -> DATE '2006-10-20' 
 DATE '2006-05-20' + INTERVAL 5 YEAR  -> DATE '2011-05-20' 
schema:gisq

In this example we show the date 7 days after the value specified in whn

SELECT whn, (whn) + 7 
  FROM gisq.eclipse
SELECT whn, (whn) + 7 
  FROM eclipse
SELECT whn, whn + DATE(7 DAY)
  FROM eclipse
SELECT whn, whn + 7 
  FROM eclipse
SELECT whn, whn+INTERVAL 7 DAY
  FROM eclipse

See also

Language: English  • Deutsch
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense