title: Azure Application Insights: How to format dates (and numbers)
body: <p>I'm in need of formatting an aggregated date in such a way that it produces an readable <strong>and</strong> sortable format. I am creating a time series that aggregates the number of requests over a period of days using the following code:</p>
  
  <pre><code>let us_date = (t:datetime)
  { 
    strcat(    getmonth(t - 8h), "-",  dayofmonth(t - 8h))
  };
  requests
  | project timestamp, client_IP, local_date = us_date(timestamp) 
  | where timestamp &gt;= now() -  30d  and timestamp &lt;= now() + 1d
  | summarize  uniqueUsers = dcount(client_IP) by usdate = us_date(timestamp)
  | order by usdate desc
  </code></pre>
  
  <p>which produces:</p>
  
  <p><a href="https://i.stack.imgur.com/DuC6a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DuC6a.png" alt="enter image description here"></a></p>
  
  <p>The data is fine, but due to the formatting the sort order is off.</p>
  
  <p>For this to sort correctly should look like <code>05-09</code>, but I can't see a way to do this sort of formatting.</p>
  
  <p>Note that I can do the following and get the data in the right <strong>order</strong> but <strong>ugly</strong> format:</p>
  
  <pre><code>let us_date = (t:datetime)
  { 
    strcat(   getyear(t - 8h) , '-', getmonth(t - 8h), "-",  dayofmonth(t - 8h))
  };
  requests
  | project timestamp, client_IP 
  | where timestamp &gt;= now() -  30d  and timestamp &lt;= now() + 1d
  | summarize  uniqueUsers = dcount(client_IP) by usdate = bin(timestamp - 8h,1d)
  | order by usdate desc
  </code></pre>
  
  <p>but this produces very verbose list view and also embeds the time into the chart.</p>
  
  <p><a href="https://i.stack.imgur.com/PfU5d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PfU5d.png" alt="enter image description here"></a></p>
  
  <p>Any ideas how to address either the number formatting issue or how to get another value into the query to allow sorting without throwing off the results? </p>