title: Azure Stream Analytics Query: Cast string to DateTime
body: <p>The input of stream analytic is <code>IoT</code> hub and it will receive a <code>JSON</code> message as such.</p>
  
  <p><strong>Data</strong>:</p>
  
  <pre><code>[
     {
        "deviceId": "testing",
        "id": "b8db8f582c474225b90b75dfed2e9c63",
        "username": "testing",
        "localtime": "24/01/2018 11:31:24",
        "b": 240,
        "e": 357,
        "AC": 0,
        "FM": 0,
        "UC": 0,
        "DL": 0,
        "DS": 0,
        "DP": 0,
        "DR": 0,
        "LB": 120,
        "ASTV": 73,
        "MSTV": 0.5,
        "ALTV": 43
     }
  ]
  </code></pre>
  
  <p>In the <code>Azure Stream Analytics</code> query, I use <code>CAST</code> function to cast the localtime from string to datetime but it failed. It is not allowed to use <code>CONVERT</code> function. </p>
  
  <pre><code>SELECT
      id as id,
      deviceId as deviceId,
      username as username,
      cast(localtime as datetime) as localtime,
      AC as AC, FM as FM, UC as UC, 
      DL as DL, DS as DS, DP as DP,
      LB as LB, ASTV as ASTV, MSTV as MSTV
  FROM
      iot
  </code></pre>
  
  <blockquote>
    <p>Cannot cast value '24/01/2018 12:58:23' to type 'datetime' in expression 'cast ( localtime as datetime )'</p>
  </blockquote>