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: 

Handle Date format in a dynamic way

Former Member
0 Kudos

Hi Experts,

I need to handle the date format in a dynamic way in different systems.

Sample Scenario:

In my DEV system i am writing a select query where i need to validate the date field which is of the format 12/31/9999.

select * from <table> where date = '12/31/9999'.

This gets relevant records & works fine in DEV system.

But when it goes to QA system the same select query fails to fetch data as the date format is 12.31.9999.

select * from <table>

where date = '12/31/9999'. --> Fails

Similarly when it is PRD system (production) the same select query fails as the date format is 12-31-9999.

select * from <table>

where date = '12/31/9999'. --> Fails

Please post your suggestions.

Thanks

Dany

5 REPLIES 5

Former Member
0 Kudos

Dates in tables should only be stored in internal format - YYYYMMDD. Type DATS should take care of this for you.

Rob

Former Member
0 Kudos

HI,

you need to take the Dynamic date format,

look at the below example:

parameters: Date type sy-datum.

data: date1(10) type c.

Write Date to Date1.

Write:/date1.

Here the Date1 will come the User fomat, it will supports all the formats which SAP supports

regards

Sudheer

Former Member
0 Kudos

Convert every date into YYYYMMDD format and then query against the database. That is the way it is stored in the database, if the field is a date type.

0 Kudos

Hi All,

Thanks. Even though the field is of type DATS in the table, but i see that the display for date field is 12/31/9999.

You mean my select will work in any system(universal) if i modify my query as below?

select * from <table> where date = '99991231'

Note: This is for select query not for display purpose.

Please help,.

Thanks,

Dany

0 Kudos

If you are looking at the date from SE16, or some other output screen, dates are converted to what is referred to as external format. But when they are stored, they are stored in internal format which is always YYYYMMDD. So when you are doing a SELECT from database table using a date field in your WHERE clause, you have to use internal format of the date (YYYYMMDD). When you output a date that you extracted onto a screen using WRITE statement, it will be converted to external format depending on user format specifications. But the date will be in internal format within your program, so if you are transferring a date from the database directly to a file, you are transferring it as YYYYMMDD. If you need it in external format, then you have to use WRITE...TO... option. See help on WRITE command.