sql - date not in format specified
<p>I have searched a bit, and can't see any questions asked that answer my question, so here it goes.</p>

<p>I am trying to get a date from the database (source is in datetime format, i.e "2015-11-30 00:00:00.000") and select it as date, but in another format. I am using Convert function for this after "googleing". First I set target format as varchar:</p>

<pre><code>Select
convert(varchar(10),ac_payout_book_dt,104) as 'Dato'
</code></pre>

<p>Result is date in correct format, i.e "30.11.2015"</p>

<p>Then I needed to sort it when automating the script, so to be able to use </p>

<pre><code>ORDER BY Dato DESC
</code></pre>

<p>... I changed my query to ...</p>

<pre><code>Select    
convert(date,ac_payout_book_dt,104) as 'Dato'
</code></pre>

<p>Now the result is in the wrong format, i.e "2015-11-30"</p>

<p>After a few rounds on the internet I also tried this without any luck</p>

<pre><code>CAST(convert(date,ac_payout_book_dt,104) AS DATE) as 'Dato'
</code></pre>

<p>Anyone that can help me to figure out where I am going the wrong way?</p>

<p>BR
Andreas</p>