<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Why does the &amp;quot;DateFormat&amp;quot; function return incorrect results? in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaa-p/13835461#M4866304</link>
    <description>&lt;P&gt;Thanks for the information!  After reading the documentation more closely I see where it says that for the "d" format.  I'm running version 12.0.1.  Is there no format to hide the leading zero on the day of the month?  That's the format I'm trying to show.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Aug 2012 11:49:40 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2012-08-22T11:49:40Z</dc:date>
    <item>
      <title>Why does the "DateFormat" function return incorrect results?</title>
      <link>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaq-p/13835457</link>
      <description>&lt;P&gt;I have a column (named TDate) defined as Date in a table.  When I type "Select TDate, dateformat(tdate, 'm/d/yyyy') as newdate" the day portion of "newdate" is not correct (in Interactive SQL).  For example, one of the rows has a date of '2012-09-15' in TDate.  The Results pane shows "2012-09-15" for TDate and "9/7/2012" in the newdate column.  I was hoping to see "9/15/2012" in the newdate column.  Has anyone else seen this behavior?&lt;BR /&gt;
&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2012 16:10:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaq-p/13835457</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-08-21T16:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the "DateFormat" function return incorrect results?</title>
      <link>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaa-p/13835458#M4866301</link>
      <description>&lt;P&gt;You don't say which version you are using, but running:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;Select&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'2012-09-15'&lt;/SPAN&gt; &lt;SPAN class="n"&gt;as&lt;/SPAN&gt; &lt;SPAN class="n"&gt;thedate&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="n"&gt;dateformat&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;thedate&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'m/d/yyyy'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="n"&gt;as&lt;/SPAN&gt; &lt;SPAN class="n"&gt;newdate&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;in 10.0.1 produces:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;thedate&lt;/SPAN&gt;      &lt;SPAN class="n"&gt;newdate&lt;/SPAN&gt;
&lt;SPAN class="o"&gt;=========&lt;/SPAN&gt;    &lt;SPAN class="o"&gt;=========&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;2012&lt;/SPAN&gt;&lt;SPAN class="o"&gt;-&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;09&lt;/SPAN&gt;&lt;SPAN class="o"&gt;-&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;15&lt;/SPAN&gt;   &lt;SPAN class="mi"&gt;09&lt;/SPAN&gt;&lt;SPAN class="sr"&gt;/7/&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;2012&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;as you say. &lt;S&gt;While it doesn't explain what those results mean, the problem is that 'm/d/yyy' is not a supported date format.&lt;/S&gt; d means ordinal day of the week - 1= Sunday etc - see Breck's answer. To get a day and month &lt;EM&gt;without&lt;/EM&gt; leading zeros you need ''Mm/Dd/yyyy' ie &lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;Select&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'2012-09-15'&lt;/SPAN&gt; &lt;SPAN class="n"&gt;as&lt;/SPAN&gt; &lt;SPAN class="n"&gt;thedate&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="n"&gt;dateformat&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;thedate&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'Mm/Dd/yyyy'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="n"&gt;as&lt;/SPAN&gt; &lt;SPAN class="n"&gt;newdate&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;which does indeed produce:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;thedate&lt;/SPAN&gt;      &lt;SPAN class="n"&gt;newdate&lt;/SPAN&gt;
&lt;SPAN class="o"&gt;=========&lt;/SPAN&gt;    &lt;SPAN class="o"&gt;=========&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;2012&lt;/SPAN&gt;&lt;SPAN class="o"&gt;-&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;09&lt;/SPAN&gt;&lt;SPAN class="o"&gt;-&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;15&lt;/SPAN&gt;   &lt;SPAN class="mi"&gt;9&lt;/SPAN&gt;&lt;SPAN class="sr"&gt;/15/&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;2012&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;The full description of the valid formats (for v12.0.1) is &lt;STRONG&gt;&lt;A href="http://dcx.sybase.com/index.html#1201/en/dbadmin/timestamp-format-option.html*d5e40774"&gt;here&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2012 17:30:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaa-p/13835458#M4866301</guid>
      <dc:creator>justin_willey</dc:creator>
      <dc:date>2012-08-21T17:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the "DateFormat" function return incorrect results?</title>
      <link>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaa-p/13835459#M4866302</link>
      <description>&lt;P&gt;d is for day number in the week (7 for Saturday), dd is for day number in the month, ddd... is for day name; see &lt;A href="http://dcx.sybase.com/index.html#1201/en/dbadmin/date-format-option.html"&gt;date_format&lt;/A&gt;. &lt;/P&gt;
&lt;PRE&gt;Select '2012-09-15' as thedate, dateformat(thedate, 'm/dd/yyyy') as newdate

thedate,newdate
'2012-09-15','9/15/2012'
&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Aug 2012 17:47:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaa-p/13835459#M4866302</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2012-08-21T17:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the "DateFormat" function return incorrect results?</title>
      <link>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaa-p/13835460#M4866303</link>
      <description>&lt;P&gt;That makes sense! There is some confusion in the documentation - the syntax page for dateformat() points to the timestamp_format option for a list of allowable formats. The info there is a bit different from that for date_format, in particular timestamp_format doesn't mention d whereas date_format does. &lt;/P&gt;
&lt;P&gt;I've added a comment in DocComment Exchange.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2012 18:26:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaa-p/13835460#M4866303</guid>
      <dc:creator>justin_willey</dc:creator>
      <dc:date>2012-08-21T18:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the "DateFormat" function return incorrect results?</title>
      <link>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaa-p/13835461#M4866304</link>
      <description>&lt;P&gt;Thanks for the information!  After reading the documentation more closely I see where it says that for the "d" format.  I'm running version 12.0.1.  Is there no format to hide the leading zero on the day of the month?  That's the format I'm trying to show.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2012 11:49:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaa-p/13835461#M4866304</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-08-22T11:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the "DateFormat" function return incorrect results?</title>
      <link>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaa-p/13835462#M4866305</link>
      <description>&lt;P&gt;For numerical days of the month with &lt;B&gt;no&lt;/B&gt; leading zeros you want 'Dd' rather than 'dd' - see the example in my answer.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2012 11:59:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaa-p/13835462#M4866305</guid>
      <dc:creator>justin_willey</dc:creator>
      <dc:date>2012-08-22T11:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the "DateFormat" function return incorrect results?</title>
      <link>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaa-p/13835463#M4866306</link>
      <description>&lt;P&gt;Try using Dd for the format... as in:&lt;/P&gt;
&lt;P&gt;select '2012-01-02' as thedate, dateformat(thedate, 'Mm/Dd/yyyy') as newdate&lt;/P&gt;
&lt;P&gt;FWIW: This is documented on dcx - &lt;A href="http://dcx.sybase.com/index.html#1201/en/dbadmin/timestamp-format-option.html"&gt;http://dcx.sybase.com/index.html#1201/en/dbadmin/timestamp-format-option.html&lt;/A&gt; - in the paragraph starting with "For symbols that represent numeric data...":
&lt;/P&gt;&lt;PRE&gt; Type the symbol in mixed case (such as Mm) to suppress zero padding. For example, yyyy/Mm/Dd could produce 2002/1/1
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2012 12:03:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaa-p/13835463#M4866306</guid>
      <dc:creator>MarkCulp</dc:creator>
      <dc:date>2012-08-22T12:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the "DateFormat" function return incorrect results?</title>
      <link>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaa-p/13835464#M4866307</link>
      <description>&lt;P&gt;That worked great!  Sorry I missed the Dd format in the earlier example.  Much appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2012 15:38:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-does-the-quot-dateformat-quot-function-return-incorrect-results/qaa-p/13835464#M4866307</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-08-23T15:38:23Z</dc:date>
    </item>
  </channel>
</rss>

