<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"><meta name="Generator" content="Microsoft Word 14 (filtered medium)"><title>Comparing Dates</title><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.E-mailStijl17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang="NL" link="blue" vlink="purple"><div class="WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Hi Johnathan,</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">How about something like:</span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;"></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;">let $asset_type_code := &quot;STY&quot;<br>
let $asset_creation_date := &quot;20111017&quot;<br>let $asset_creation_date_start := xs:dateTime(fn:replace($asset_creation_date, &quot;^(\d{4})(\d{2})(\d{2})$&quot;, &quot;$1-$2-$3T00:00:00&quot;))<br>let $asset_creation_date_end := $asset_creation_date_start + xs:dayTimeDuration(&quot;P1D&quot;)<br>
<br></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;">return</span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;"> doc()[//assetTypeCode = $asset_type_code][//firstCreated &gt;= $asset_creation_date_start][//firstCreated &lt; $asset_creation_date_end]/*<br>
<br></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">It might perform better though if youd rewrite to for instance:</span></p><p class="MsoNormal">
<span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;"></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;">cts:search(</span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;"> doc(),</span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;"> cts:and-query((</span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;"> cts:element-value-query(xs:QName(&quot;assetTypeCode&quot;), $asset_type_code),</span></p><p class="MsoNormal">
<span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;"> cts:element-range-query(xs:QName(&quot;firstCreated&quot;), &quot;&gt;=&quot;, $asset_creation_date_start),</span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;"> cts:element-range-query(xs:QName(&quot;firstCreated&quot;), &quot;&lt;&quot;, $asset_creation_date_end)</span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;"> ))</span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;">)/*<br>
<br></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">This requires a few indexes though..</span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Kind regards,</span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Geert</span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"></span></p><div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm"><p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">Van:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href="mailto:general-bounces@developer.marklogic.com">general-bounces@developer.marklogic.com</a> [mailto:<a href="mailto:general-bounces@developer.marklogic.com">general-bounces@developer.marklogic.com</a>] <b>Namens </b>Jonathan Cook<br>
<b>Verzonden:</b> donderdag 8 maart 2012 17:59<br><b>Aan:</b> MarkLogic Developer Discussion<br><b>Onderwerp:</b> [MarkLogic Dev General] Comparing Dates</span></p></div></div><p class="MsoNormal"></p><p class="MsoNormal">
<span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;">Hi,<br><br>I wondered what the best way to compare dates using mark logic xquery was?<br><br>My query looks like this at the moment:<br>
<br>import module namespace xinc = &quot;<a href="http://marklogic.com/xinclude">http://marklogic.com/xinclude</a>&quot; at &quot;/MarkLogic/xinclude/xinclude.xqy&quot;;<br><br>let $asset_type_code := &quot;STY&quot;<br>let $asset_creation_date := &quot;20111017&quot;<br>
<br>let $results := /*[<br>/*/itemMeta/assetTypeCode[text()=$asset_type_code] and /*/itemMeta/firstCreated[text()=&#39;2011-10-17T14:47:52+00:00&#39;] <br>]<br><br>return $results<br><br>However what I would like to do is use the $asset_creation_date variable which would be of format yyyyMMdd and see if it equals the first part of the firstCreated element which is in a different format as above? There doesnt seem to be many date time functions and also Im not sure if Im going about this slightly the wrong way or if I would have to do it in a second FLOWR statement using some string comparison?<br>
<br>Thanks<br>Jon</span> </p><div><p class="MsoNormal"></p></div><p class="MsoNormal"><br><a href="http://www.bbc.co.uk">http://www.bbc.co.uk</a><br>This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated.<br>
If you have received it in error, please delete it from your system.<br>Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately.<br>Please note that the BBC monitors e-mails sent or received.<br>
Further communication will signify your consent to this. </p></div></div></body></html>