Application Development and Automation 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: 
Read only

change date format in select statement

shobhan_rana
Explorer
0 Likes
5,615

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
Read only

Sandra_Rossi
Active Contributor
4,961

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

Read only

FredericGirod
Active Contributor
4,961

so strange to require a date format in a SELECT statement

Read only

shobhan_rana
Explorer
0 Likes
4,961

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 '-'.

Read only

FredericGirod
Active Contributor
0 Likes
4,961

but ERDAT is type Date ? or type CHAR10 ?

Read only

shobhan_rana
Explorer
0 Likes
4,961

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

Read only

Sandra_Rossi
Active Contributor
4,961

You have the following SQL functions:

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

Jelena_Perfiljeva
Active Contributor
0 Likes
4,961

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.