<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Le blog de jsd03 &#187; date</title>
	<atom:link href="https://blog.developpez.com/jsd03/ptag/date/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/jsd03</link>
	<description></description>
	<lastBuildDate>Mon, 07 Nov 2016 14:34:06 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Création calendrier</title>
		<link>https://blog.developpez.com/jsd03/p13114/bdd/creation-calendrier</link>
		<comments>https://blog.developpez.com/jsd03/p13114/bdd/creation-calendrier#comments</comments>
		<pubDate>Fri, 21 Oct 2016 15:20:04 +0000</pubDate>
		<dc:creator><![CDATA[jsd03]]></dc:creator>
				<category><![CDATA[Base de données]]></category>
		<category><![CDATA[MSSQL Server]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[calendrier]]></category>
		<category><![CDATA[date]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/jsd03/?p=134</guid>
		<description><![CDATA[La requête suivante permet de générer une table &#171;&#160;Calendar&#160;&#187; avec Sql Server du 01/01/1900 au 12/31/2999 : 12345678910111213141516171819202122232425262728293031SELECT &#160; &#160; convert(date , d ) as CalDate, &#160; &#160; DATEPART(YEAR, d) as CalYear, &#160; &#160; DATEPART(QUARTER, &#160;d) as CalQuarter, &#160; &#160; &#8230; <a href="https://blog.developpez.com/jsd03/p13114/bdd/creation-calendrier">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>La requête suivante permet de générer une table &laquo;&nbsp;Calendar&nbsp;&raquo; avec Sql Server du 01/01/1900 au 12/31/2999 :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT<br />
&nbsp; &nbsp; convert(date , d ) as CalDate,<br />
&nbsp; &nbsp; DATEPART(YEAR, d) as CalYear,<br />
&nbsp; &nbsp; DATEPART(QUARTER, &nbsp;d) as CalQuarter,<br />
&nbsp; &nbsp; DATEPART(MONTH, &nbsp;d) as CalMonth,<br />
&nbsp; &nbsp; DATENAME(MONTH, &nbsp; &nbsp;d) as CalMonthName,<br />
&nbsp; &nbsp; DATEPART(WEEK, &nbsp; &nbsp; d) as CalWeekOfYear,<br />
&nbsp; &nbsp; CONVERT(CHAR(10), &nbsp;d, 101) as CalDateStr,<br />
&nbsp; &nbsp; DATEPART(WEEKDAY, &nbsp;d) as CalDayOfWeek,<br />
&nbsp; &nbsp; DATEPART(DAY, &nbsp;d) as CalDayOfMonth,<br />
&nbsp; &nbsp; DATEPART(dy, d) as CalDayOfYear,<br />
&nbsp; &nbsp; CONVERT(VARCHAR(10), DATENAME(WEEKDAY, d)) as CalDayName,<br />
&nbsp; &nbsp; DATEPART(YEAR, d)*100+REPLACE(STR(DATEPART(MONTH, &nbsp;d), 4), SPACE(1), '0') as CalYearMonth,<br />
&nbsp; &nbsp; DATEPART(YEAR, d)*10000+REPLACE(STR(DATEPART(MONTH, &nbsp;d), 4), SPACE(1), '0')*100+DATEPART(DAY, &nbsp;d) as CalYearDay,<br />
&nbsp; &nbsp; CASE WHEN REPLACE(STR(DATEPART(MONTH, &nbsp;d), 4), SPACE(1), '0')*100+DATEPART(DAY, &nbsp;d) IN (101, 501, 508, 714,815, 1101, 1225) THEN 1 ELSE 0 &nbsp;END as CalIsPublicHoliday,<br />
&nbsp; &nbsp; case when DATEPART(WEEKDAY, &nbsp;d) in (6, 7) THEN 1 else 0 end as CalIsWeekEnd<br />
&nbsp; &nbsp; into dbo.Calendar<br />
from<br />
(<br />
SELECT d = DATEADD(DAY, rn - 1, '19000101')<br />
&nbsp; FROM <br />
&nbsp; (<br />
&nbsp; &nbsp; SELECT TOP (DATEDIFF(DAY, '19000101', '29991231')) <br />
&nbsp; &nbsp; &nbsp; rn = ROW_NUMBER() OVER (ORDER BY s1.[object_id])<br />
&nbsp; &nbsp; FROM sys.all_objects AS s1<br />
&nbsp; &nbsp; CROSS JOIN sys.all_objects AS s2<br />
&nbsp; &nbsp; ORDER BY s1.[object_id]<br />
&nbsp; ) A<br />
) b;<br />
<br />
create index IdxRefCalendar on dbo.[REF-Calendar](CalDate);</div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajouter une année à une date</title>
		<link>https://blog.developpez.com/jsd03/p11726/bdd/ajouter-une-annee-a-une-date</link>
		<comments>https://blog.developpez.com/jsd03/p11726/bdd/ajouter-une-annee-a-une-date#comments</comments>
		<pubDate>Wed, 16 Jan 2013 21:12:23 +0000</pubDate>
		<dc:creator><![CDATA[jsd03]]></dc:creator>
				<category><![CDATA[Base de données]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[ajouter]]></category>
		<category><![CDATA[année]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[interval]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/jsd03/?p=53</guid>
		<description><![CDATA[Pour ajouter une année à une date on aurait tendance à faire : 1select sysdate + 365 AS ANNEE_SUP from dual; Ou : 1select ADD_MONTHS(sysdate, 12) AS ANNEE_SUP from dual; Mais en fin de compte la bonne syntaxe est : &#8230; <a href="https://blog.developpez.com/jsd03/p11726/bdd/ajouter-une-annee-a-une-date">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Pour ajouter une année à une date on aurait tendance à faire :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">select sysdate + 365 AS ANNEE_SUP from dual;</div></td></tr></tbody></table></div>
<p>Ou :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">select ADD_MONTHS(sysdate, 12) AS ANNEE_SUP from dual;</div></td></tr></tbody></table></div>
<p>Mais en fin de compte la bonne syntaxe est :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">select sysdate + interval '1' year AS ANNEE_SUP &nbsp;from dual;</div></td></tr></tbody></table></div>
<p><span id="more-53"></span><br />
Effectivement :</p>
<ul>
<li>la première solution suivant si on se place dans une année bissextile ou pas ne fonctionnera pas</li>
<li>la seconde solution de ce que j&rsquo;ai pu en lire sur un site officiel Oracle ne marche pas non plus à tous les coups encore une fois à cause de ces années bissextiles&#8230;</li>
<li>du coup ajouter un intervalle fonctionnel à 100% ! alors surtout quand vous voulez ajouter une année à une date utiliser &laquo;&nbsp;interval&nbsp;&raquo; !</li>
</ul>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Création et alimentation d&#8217;une dimension DATE</title>
		<link>https://blog.developpez.com/jsd03/p11721/bdd/creation-et-alimentation-dune-dimension-date</link>
		<comments>https://blog.developpez.com/jsd03/p11721/bdd/creation-et-alimentation-dune-dimension-date#comments</comments>
		<pubDate>Tue, 15 Jan 2013 22:20:57 +0000</pubDate>
		<dc:creator><![CDATA[jsd03]]></dc:creator>
				<category><![CDATA[Base de données]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[dimension]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/jsd03/?p=26</guid>
		<description><![CDATA[Lors de la création d&#8217;un entrepôt de données, bien souvent, il contient une dimension DATE contenant la liste des dates depuis l&#8217;année 1900 jusqu&#8217;à l&#8217;année 2999. Cette table contenant plusieurs attributs comme par exemple : La date au format date &#8230; <a href="https://blog.developpez.com/jsd03/p11721/bdd/creation-et-alimentation-dune-dimension-date">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Lors de la création d&rsquo;un entrepôt de données, bien souvent, il contient une dimension DATE contenant la liste des dates depuis l&rsquo;année 1900 jusqu&rsquo;à l&rsquo;année 2999. Cette table contenant plusieurs attributs comme par exemple :</p>
<ul>
<li>La date au format date</li>
<li>La date au format chaine de caractère sous la forme DD/MM/YYYY</li>
<li>La date au format numérique sous la forme YYYYMMDD</li>
<li>Le jour de l&rsquo;année</li>
<li>&#8230;</li>
</ul>
<p>Voici donc un exemple de création de DIM_DATE en Oracle.<br />
<span id="more-26"></span><br />
Tout d&rsquo;abord la description de la DIM_DATE :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">create table DIM_DATE<br />
(<br />
&nbsp; &nbsp;ID_DATE &nbsp; &nbsp; &nbsp; &nbsp;NUMBER(8) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;not null,<br />
&nbsp; &nbsp;DATE_DU_JOUR &nbsp; &nbsp; &nbsp; &nbsp; DATE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; not null,<br />
&nbsp; &nbsp;ANNEE_CALENDAIRE &nbsp; &nbsp; NUMBER(4),<br />
&nbsp; &nbsp;SEMESTRE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NUMBER(1),<br />
&nbsp; &nbsp;LIBELLE_SEMESTRE &nbsp; &nbsp; VARCHAR2(250 CHAR),<br />
&nbsp; &nbsp;TRIMESTRE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NUMBER(1),<br />
&nbsp; &nbsp;LIBELLE_TRIMESTRE &nbsp; &nbsp;VARCHAR2(250 CHAR),<br />
&nbsp; &nbsp;ANNEE_MOIS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NUMBER(6),<br />
&nbsp; &nbsp;MOIS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NUMBER(2),<br />
&nbsp; &nbsp;LIBELLE_MOIS &nbsp; &nbsp; &nbsp; &nbsp; VARCHAR2(250 CHAR),<br />
&nbsp; &nbsp;SEMAINE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NUMBER(2),<br />
&nbsp; &nbsp;JOUR &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NUMBER(2),<br />
&nbsp; &nbsp;LIBELLE_JOUR &nbsp; &nbsp; &nbsp; &nbsp; VARCHAR2(250 CHAR),<br />
&nbsp; &nbsp;JOUR_FERIE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CHAR(3 CHAR),<br />
&nbsp; &nbsp;JOUR_OUVRE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CHAR(3 CHAR),<br />
&nbsp; &nbsp;QUANTIEME_JOUR &nbsp; &nbsp; &nbsp; NUMBER<br />
);</div></td></tr></tbody></table></div>
<p>Et son chargement avec un simple ordre INSERT et une requête SELECT hiérarchique :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">INSERT INTO DIM_DATE (ID_DATE, DATE_DU_JOUR, ANNEE_CALENDAIRE, SEMESTRE, LIBELLE_SEMESTRE, TRIMESTRE, LIBELLE_TRIMESTRE, ANNEE_MOIS,MOIS, LIBELLE_MOIS, SEMAINE, JOUR, LIBELLE_JOUR, JOUR_FERIE, JOUR_OUVRE, QUANTIEME_JOUR)<br />
SELECT<br />
&nbsp; &nbsp; TO_NUMBER(TO_CHAR(DT_CAL, 'YYYYMMDD')) AS ID_CALENDRIER,<br />
&nbsp; &nbsp; DT_CAL AS DATE_DU_JOUR,<br />
&nbsp; &nbsp; TO_NUMBER(TO_CHAR(DT_CAL, 'YYYY')) AS ANNEE_CALENDAIRE,<br />
&nbsp; &nbsp; ROUND(TO_NUMBER(TO_CHAR(DT_CAL, 'Q'))/2) AS SEMESTRE,<br />
&nbsp; &nbsp; CASE ROUND(TO_NUMBER(TO_CHAR(DT_CAL, 'Q'))/2) WHEN 1 THEN '1er semestre' ELSE '2ème semestre' END AS LIBELLE_SEMESTRE,<br />
&nbsp; &nbsp; TO_NUMBER(TO_CHAR(DT_CAL, 'Q')) AS TRIMESTRE,<br />
&nbsp; &nbsp; CASE TO_NUMBER(TO_CHAR(DT_CAL, 'Q')) WHEN 1 THEN '1er trimestre' ELSE TO_NUMBER(TO_CHAR(DT_CAL, 'Q')) || 'ème trimestre' END AS LIBELLE_TRIMESTRE,<br />
&nbsp; &nbsp; TO_NUMBER(TO_NUMBER(TO_CHAR(DT_CAL, 'YYYY')) || LPAD(TO_CHAR(DT_CAL, 'MM'), 2, '0')) AS ANNEE_MOIS,<br />
&nbsp; &nbsp; TO_NUMBER(TO_CHAR(DT_CAL, 'MM')) AS MOIS,<br />
&nbsp; &nbsp; TO_CHAR(DT_CAL, 'Month') AS LIBELLE_MOIS,<br />
&nbsp; &nbsp; TO_NUMBER(TO_CHAR(DT_CAL, 'IW')) AS SEMAINE,<br />
&nbsp; &nbsp; TO_NUMBER(TO_CHAR(DT_CAL, 'DD')) AS JOUR,<br />
&nbsp; &nbsp; TO_CHAR(DT_CAL, 'Day') AS LIBELLE_JOUR,<br />
&nbsp; &nbsp; CASE WHEN TO_CHAR(DT_CAL, 'D') IN ('6', '7') THEN 'Oui' ELSE 'Non' END AS JOUR_FERIE,<br />
&nbsp; &nbsp; CASE WHEN TO_CHAR(DT_CAL, 'D') IN ('6', '7') THEN 'Non' ELSE 'Oui' END AS JOUR_OUVRE,<br />
&nbsp; &nbsp; NUM_JOUR AS QUANTIEME_JOUR<br />
FROM<br />
(<br />
&nbsp; &nbsp; SELECT to_date('19000101','YYYYMMDD') + (rownum - 1) AS DT_CAL, rownum AS NUM_JOUR<br />
&nbsp; &nbsp; FROM dual<br />
&nbsp; &nbsp; connect BY to_date('19000101','YYYYMMDD') + (rownum - 1) &amp;lt;= to_date(&amp;#039;29991231&amp;#039;,&amp;#039;YYYYMMDD&amp;#039;)<br />
);<br />
&nbsp;<br />
COMMIT;</div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
