Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

change date format in select statement

shobhan_rana
Explorer
0 Kudos

Hi all,

i want to convert ERDAT to YYYY-MM-DD format directly in select statement in Database - MSSQL.

Date format YYYYMMDD to YYYY-MM-DD. is it possible?

Regards

7 REPLIES 7

Sandra_Rossi
Active Contributor

Of course but the solution depends on the context of your development. Please clarify.

FredericGirod
Active Contributor

so strange to require a date format in a SELECT statement

shobhan_rana
Explorer
0 Kudos

It works like follows but too late to do it in outside select.

CONCATENATE ls_out-erdat+0(4)

ls_out-erdat+4(2)

ls_out-erdat+6(2) INTO ls_out-erdat SEPARATED BY '-'.

FredericGirod
Active Contributor
0 Kudos

but ERDAT is type Date ? or type CHAR10 ?

shobhan_rana
Explorer
0 Kudos

Context is as follow. It is a normal select like ::

ERDAT ist 10 CHAR long.

REPORT ZCONTEXT.

Select single

CAST( erdat AS CHAR( 10 ) ) AS erdat,

from KNA1.

I just want to place "-" in between the year, month and date inside the select statement. so that it is JSON compatible date => YYYY-MM-DD

Thanks

Sandra_Rossi
Active Contributor

You have the following SQL functions:

  • CONCAT (also &&)
  • LEFT, SUBSTRING, RIGHT

Jelena
Active Contributor
0 Kudos

Sorry, this is really rather RTFM question that is impossible to answer without knowing technical details. You've mentioned it's MS SQL, so I'm guessing it's an older system and CDS views are not applicable in your case.

Look up documentation for SELECT statement for your ABAP version (use F1). All the functions will be described there, I doubt anyone can tell you something different here. There is also Native SQL option (which is covered in documentation) but I doubt it'll help or would be a good idea.

I'm curious about the context though and why is it important to do this in SELECT statement directly. I doubt it'll give you any "code pushdown" benefits.