title: Azure Data Factory - querying Cosmos DB using dynamic timestamps
body: <p>I want to create and maintain a snapshot of a collection in Cosmos DB.</p>
  <p>Periodically, I want to retrieve only the delta (new or modified documents) from Cosmos and write them to the snapshot, which will be stored in a Azure Data Explorer cluster.</p>
  <p>I wish to get the delta using the _ts member of the documents. In other words, I will fetch only records for which the _ts is between some range.</p>
  <p>The range will be the range of a time window, which I get using a tumbling window trigger in the data factory.</p>
  <p>The issue is that if I print the dynamic timestamps which I create in the query, and hard code them into the query, it works. But if I let the query generate them, I don't get any results.</p>
  <p>For example:</p>
  <p>I'm using those value to simulate the window range of the trigger.</p>
  <p><a href="https://i.stack.imgur.com/ykAc2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ykAc2.png" alt="enter image description here" /></a></p>
  <p>I use this query to create timestamps in unix time.</p>
  <p><a href="https://i.stack.imgur.com/Mq719.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mq719.png" alt="enter image description here" /></a></p>
  <p>and I see that the timestamps created are correct.</p>
  <p><a href="https://i.stack.imgur.com/G4HQ0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G4HQ0.png" alt="enter image description here" /></a></p>
  <p>And if I run my query using those hardcoded timestamps, I get results</p>
  <p><a href="https://i.stack.imgur.com/ZRrE0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZRrE0.png" alt="enter image description here" /></a></p>
  <p>But, if I run a query using the code that just create those timestamps, I get no results from the query</p>
  <p><a href="https://i.stack.imgur.com/8DS8i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8DS8i.png" alt="enter image description here" /></a></p>
  <p>This is the code to create the timestamps:</p>
  <pre><code>select 
  DateTimeToTimestamp('@{formatDateTime('2020-05-20T12:00:00.0000000Z','yyyy-MM
  ddTHH:mm:ss.fffffffZ')}')/1000,
  DateTimeToTimestamp('@{formatDateTime('2020-08-20T12:00:00.0000000Z','yyyy-MM
  ddTHH:mm:ss.fffffffZ')}')/1000
  </code></pre>
  <p>Does anyone have a clue as to what might be the issue?</p>
  <p>Any other way to achieve this is also welcome.</p>
  <p>Thanks</p>
  <p>EDIT: I managed to work around this by taking the other, simpler option:</p>
  <pre><code>where TimestampToDateTime(c._ts*1000)&gt; &quot;@{formatDateTime(pipeline().parameters.windowStart,'yyyy-MM-ddTHH:mm:ss.fffffffZ')}&quot;
  </code></pre>