<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://sqlzoo.net/w/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://sqlzoo.net/w/index.php?title=Substract_dates&amp;feed=atom&amp;action=history</id>
		<title>Substract dates - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://sqlzoo.net/w/index.php?title=Substract_dates&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Substract_dates&amp;action=history"/>
		<updated>2013-05-20T01:49:55Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.4</generator>

	<entry>
		<id>http://sqlzoo.net/w/index.php?title=Substract_dates&amp;diff=1685&amp;oldid=prev</id>
		<title>Marek at 09:10, 18 July 2012</title>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Substract_dates&amp;diff=1685&amp;oldid=prev"/>
				<updated>2012-07-18T09:10:16Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 09:10, 18 July 2012&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 71:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 71:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class=&amp;quot;ecomm e-mysql&amp;quot; style=&amp;quot;display: none&amp;quot;&amp;gt;We may use the TO_DAYS function which tells use how many&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class=&amp;quot;ecomm e-mysql&amp;quot; style=&amp;quot;display: none&amp;quot;&amp;gt;We may use the TO_DAYS function which tells use how many&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;days since year 0.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;days since year 0.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;See [http://www.mysql.com/doc/en/Date_and_time_functions.html &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;See [http://www.mysql.com/doc/en/Date_and_time_functions.html Date and Time Functions] for more details.&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;6.3.4 &lt;/del&gt;Date and Time Functions] for more details.&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class=&amp;quot;ecomm e-sqlserver&amp;quot; style=&amp;quot;display: none&amp;quot;&amp;gt;We can get the answer in days, or in years.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class=&amp;quot;ecomm e-sqlserver&amp;quot; style=&amp;quot;display: none&amp;quot;&amp;gt;We can get the answer in days, or in years.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Marek</name></author>	</entry>

	<entry>
		<id>http://sqlzoo.net/w/index.php?title=Substract_dates&amp;diff=1532&amp;oldid=prev</id>
		<title>Marek: Created page with &quot;Subtract dates. &lt;div class='ht'&gt; &lt;div class=params&gt;schema:scott&lt;/div&gt; &lt;div&gt; SQL Standard allows dates to be subtracted. We specify the unit and the number of digits of the res...&quot;</title>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Substract_dates&amp;diff=1532&amp;oldid=prev"/>
				<updated>2012-07-17T14:51:12Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;Subtract dates. &amp;lt;div class=&amp;#039;ht&amp;#039;&amp;gt; &amp;lt;div class=params&amp;gt;schema:scott&amp;lt;/div&amp;gt; &amp;lt;div&amp;gt; SQL Standard allows dates to be subtracted. We specify the unit and the number of digits of the res...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Subtract dates.&lt;br /&gt;
&amp;lt;div class='ht'&amp;gt;&lt;br /&gt;
&amp;lt;div class=params&amp;gt;schema:scott&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div&amp;gt;&lt;br /&gt;
SQL Standard allows dates to be subtracted. We specify the unit&lt;br /&gt;
and the number of digits of the result answer:&lt;br /&gt;
YEAR MONTH DAY HOUR MINUTE SECOND&lt;br /&gt;
&lt;br /&gt;
We want to know how long has it been since Tom Jones featured&lt;br /&gt;
on TOTP.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=sql class='tidy'&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;source lang=sql class='setup'&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='sql' class='def e-sqlite'&amp;gt;&lt;br /&gt;
SELECT singer, song, wk,&lt;br /&gt;
  (JULIANDAY(CURRENT_DATE) - JULIANDAY(wk))&lt;br /&gt;
  FROM totp&lt;br /&gt;
 WHERE singer = 'Tom Jones'&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='sql' class='def e-oracle'&amp;gt;&lt;br /&gt;
SELECT singer, song, ROUND(SYSDATE - wk) &amp;quot;days&amp;quot;&lt;br /&gt;
  FROM gisq.totp&lt;br /&gt;
 WHERE singer = 'Tom Jones'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='sql' class='def e-postgres'&amp;gt;&lt;br /&gt;
SELECT singer, song,&lt;br /&gt;
  CURRENT_DATE - wk AS days&lt;br /&gt;
  FROM totp&lt;br /&gt;
 WHERE singer = 'Tom Jones'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='sql' class='def e-access'&amp;gt;&lt;br /&gt;
SELECT singer, song, INT(NOW()- wk) AS &amp;quot;DAYS&amp;quot;&lt;br /&gt;
  FROM totp&lt;br /&gt;
 WHERE singer = 'Tom Jones'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='sql' class='def e-mysql'&amp;gt;&lt;br /&gt;
USE gisq;&lt;br /&gt;
SELECT singer, song,&lt;br /&gt;
 TO_DAYS(NOW()) - TO_DAYS(wk) &amp;quot;DAYS&amp;quot;&lt;br /&gt;
 FROM totp&lt;br /&gt;
WHERE singer = 'Tom Jones'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='sql' class='def e-sqlserver'&amp;gt;&lt;br /&gt;
SELECT singer, song,&lt;br /&gt;
       DATEDIFF(&amp;quot;d&amp;quot;,wk,GETDATE()) &amp;quot;DAYS&amp;quot;,&lt;br /&gt;
       DATEDIFF(yyyy,wk,GETDATE()) &amp;quot;YEARS&amp;quot;&lt;br /&gt;
  FROM totp&lt;br /&gt;
 WHERE singer = 'Tom Jones'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='sql' class='def'&amp;gt;&lt;br /&gt;
SELECT singer, song, wk,&lt;br /&gt;
  (CURRENT_DATE - wk) DAY(5) &amp;quot;days&amp;quot;&lt;br /&gt;
  FROM totp&lt;br /&gt;
 WHERE singer = 'Tom Jones'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;ecomm e-db2&amp;quot; style=&amp;quot;display: none&amp;quot;&amp;gt;The [https://aurora.vcu.edu/db2help/db2s0/sqls0415.htm#HDRFNDAYS DAYS] function gives us the number of days since a long time ago.&lt;br /&gt;
The string &amp;quot;yymmdd&amp;quot; includes the number of years, months and days since.&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;ecomm e-oracle&amp;quot; style=&amp;quot;display: none&amp;quot;&amp;gt;If we subtract two dates we get the lengths of time measured in days.&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;ecomm e-mysql&amp;quot; style=&amp;quot;display: none&amp;quot;&amp;gt;We may use the TO_DAYS function which tells use how many&lt;br /&gt;
days since year 0.&lt;br /&gt;
See [http://www.mysql.com/doc/en/Date_and_time_functions.html &lt;br /&gt;
6.3.4 Date and Time Functions] for more details.&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;ecomm e-sqlserver&amp;quot; style=&amp;quot;display: none&amp;quot;&amp;gt;We can get the answer in days, or in years.&lt;br /&gt;
[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_da-db_5vxi.asp MSDN documentation on DATEDIFF]&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
{{DATE and TIME ref}}&lt;/div&gt;</summary>
		<author><name>Marek</name></author>	</entry>

	</feed>