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: 

FM: DATE_TO_DAY

Former Member
0 Kudos
2,081

Hi,

I have a requirement where i have to convert the given to a weekday.I got the FM DATE_TO_DAY.,but i am getting wrong output when i use the same in my program.

In the internal table i have declared date1 as sydatum and the weekday as char(10).

I am not able to get where i am wrong.

Kindly help me out.

Thanks and Regards

Yamini.A

21 REPLIES 21

former_member188685
Active Contributor
0 Kudos
398

Hi Yamini,

please give your code so that i can find out what is the problem.

convert the Char to Date and then assign.

use this fm CONVERT_DATE_TO_INTERNAL

regards

vijay.

athavanraja
Active Contributor
0 Kudos
398

i just checked with randamly choosen dates and it works fine.

is there a specific date for which it gives wrong output or for all dates.

Regards

Raja

Former Member
0 Kudos
398

Hi please run this following code..

it will give you idea about this FM,

please reward point if it helps you.

REPORT ZANID_TEST4 MESSAGE-ID zz.

*

data: begin of itab occurs 0,

date1 like sy-datum,

day like DTRESR-WEEKDAY,

end of itab.

**--populating internal table with sample data

itab-date1 = '20051128'.

append itab.

itab-date1 = '20051129'.

append itab.

itab-date1 = '20051130'.

append itab.

*---calling FM

loop at itab.

CALL FUNCTION 'DATE_TO_DAY'

EXPORTING

date = itab-date1

IMPORTING

WEEKDAY = itab-day.

modify itab.

endloop.

*-----outputting data

loop at itab.

write:/ itab-date1,itab-day.

endloop.

Former Member
0 Kudos
398

Hi,

In the FM i have given the date as 28.11.2005 ,the weekday should be monday but for me it is showing as saturday.

I am not able to get where i am wrong.

My piece of code is :

based on a query i am fetching the value of workdate and then i have used the foll query

concatenate t_a-workdate6(2) t_a-workdate4(2)

t_a-workdate+0(4) into t_final-date1.

CALL FUNCTION 'DATE_TO_DAY'

EXPORTING

date = t_final-date1

IMPORTING

WEEKDAY = t_final-week1

.

Here i tested with yday date it is giving me a wrong output.

Thanks and Regards

Yamini.A

0 Kudos
398

i guess i found the issue.

if the date is not passed as per user format you will get problem.

for example my date format is mm/dd/yyyy when i used this format it gave the right result.

instead i tried passing dd/mm/yyyy and it gave wrong answers.

check the date format using usr01-datfm and pass the date accordingly.

Regards

Raja

0 Kudos
398

the logic for building date as per user format.

 if wf_datfm eq '1' .
    concatenate loc_date+6(2)
                loc_date+4(2)
                loc_date+0(4)
                into wf_date separated by '.' .
    condense wf_date .

  elseif wf_datfm eq '2' .
    concatenate loc_date+4(2)
                loc_date+6(2)
                loc_date+0(4)
                into wf_date separated by '/' .
    condense wf_date .

  elseif wf_datfm eq '3' .
    concatenate loc_date+4(2)
                  loc_date+6(2)
                  loc_date+0(4)
                  into wf_date separated by '-' .
    condense wf_date .
  elseif wf_datfm eq '4' .
    concatenate loc_date+0(4)
                  loc_date+4(2)
                  loc_date+6(2)
                  into wf_date separated by '.' .
    condense wf_date .
  elseif wf_datfm eq '5' .
    concatenate loc_date+0(4)
                  loc_date+4(2)
                  loc_date+6(2)
                  into wf_date separated by '/' .
    condense wf_date .
  elseif wf_datfm eq '6' .
    concatenate loc_date+0(4)
                  loc_date+4(2)
                  loc_date+6(2)
                  into wf_date separated by '-' .
    condense wf_date .
  endif .

Regards

Raja

0 Kudos
398

Hi,

Just now I checked the same FM in SE37.

It is working fine and giving correct output.

Do one thing before passing the parameter to FM check the value of it.

In debug check the value of T_FINAL-DATE1.

I hope the value you are passing to it might be wrong.

Check........

Thanks.

If this helps award points and close the thread.

0 Kudos
398

hi Yamini, if you enter some invalid values then it is

giving saturday . that means you are passing differently

u try to pass mm.dd.yyyy

then it will come, instead of dd.mm.yyyy

i checked it with ur date it gave sat.

because that is invalid, for invalid dates it is giving saturday. try to keep break point and find sy-subrc

it will not be zero.

solution is pass mm.dd.yyyy format

regards

vijay

0 Kudos
398

try to pass date in mm.dd.yyyy format not dd.mm.yyyy format.

regards

vijay

Former Member
0 Kudos
398

Hi,

I tried using dd.mm.yyyy format . so it was giving me an error.

When i tested the data with mm.dd.yyyy in se37 with the FM it gives me to give correct input date.

The date which i gave was 28.11.2005.

as per your suggesstion i gave as 11.28.2005 .. it gave me error

Kinldy let me know.

Regarda

Yamini

0 Kudos
398

Hi,

Give like this.....

11/28/2005 instead of 11.28.2005

Thanks.

This will clear your error.

Award points if it works for you.

Message was edited by: Deepak333 k

0 Kudos
398

Hi,

try that and debug:

PARAMETERS date LIKE sy-datum DEFAULT sy-datum.

DATA day LIKE dtresr-weekday.

CALL FUNCTION 'DATE_TO_DAY'

EXPORTING

date = date

IMPORTING

weekday = day.

WRITE: / date , day.

Andreas

Former Member
0 Kudos
398

You can try this,

parameter D1 like SCAL-DATE.

data D2 like SCAL-INDICATOR.

CALL FUNCTION 'DATE_COMPUTE_DAY'

EXPORTING

date = d1

IMPORTING

DAY = d2

.

It will give the day.

If it is 1 then Monday 2 Tuesday 3 Wednesday like that

Former Member
0 Kudos
398

yamini,

First Do one thing!!

check in USR01 table datfm for the format u shud go for.

Supply the value according to that.

NOTE: some FMs won't work for different formats.

Oneway u can change the format of urs.

GOTO system menu:

USer profile->owndata..

In that select default values change the format to mm/dd/yyyy ..if u have currently a format other than this.

Cheers,

Raja

0 Kudos
398

as i said before you have to use the correct date format as per the setting in the user profile. (user01-datfm)

otherwise you are bound to get wrong results.

Regards

Raja

Former Member
0 Kudos
398

Yamini,

I gave like this.It is working for me.

Here The date Sd be of this format...

"11/20/2005"

Parameter D1 LIKE SY-DATUM.

Data D2 LIKE DTRESR-WEEKDAY.

CALL FUNCTION 'DATE_TO_DAY'

EXPORTING

DATE = D1

IMPORTING

WEEKDAY = D2

.

write D2.

Former Member
0 Kudos
398

Hi Yamini

I have checked the function Date_to_day, the function is all right.

The problem may be U have not defined the text elements.

Here is the Solution for both getting day into char type.

Make a bit changes in FM DATE_TO_DAY

I m using it by converting to ZDATE_TO_DAY

You have to declare 1 more exporting parameter i.e. day of type char10

FUNCTION ZDATE_TO_DAY.

*"----

-


""Local Interface:

*" IMPORTING

*" REFERENCE(DATE) TYPE SYDATUM

*" EXPORTING

*" REFERENCE(WEEKDAY) TYPE DTRESR-WEEKDAY

*" REFERENCE(DAY) TYPE CHAR10

*"----

-


DATA: day_p TYPE p.

day_p = date MOD 7.

  • DAY_P enthält 0 für Samstag, 1 für Sonntag, etc.. und muß

  • der Kalendernotation: 1 für Montag, 2 für Dienstag, etc.,

  • angepaßt werden.

IF day_p > 1.

day_p = day_p - 1.

ELSE.

day_p = day_p + 6.

ENDIF.

CASE day_p.

WHEN 1.

weekday = 'Monday'. "Text elements used earlier"

WHEN 2.

weekday = 'Tuesday'. " i have replaced with Monday Tuesday.......

WHEN 3.

weekday = 'Wednesday'.

WHEN 4.

weekday = 'Thursday'.

WHEN 5.

weekday = 'Friday'.

WHEN 6.

weekday = 'Saturday'.

WHEN 7.

weekday = 'Sunday'.

ENDCASE.

day = weekday.

write:/ day.

ENDFUNCTION.

**********************************************

Here i m getting the value of weekday in day which is of char type.

ABAP Program:-

REPORT ZSDATE.

parameter date1 type sydatum.

CALL FUNCTION 'ZDATE_TO_DAY'

EXPORTING

date = date1

  • IMPORTING

  • WEEKDAY =

  • DAY =

I m using a parameter to get the date and printing it on screen u can get it from internal table. Now no need to define weekday of type char etc.

If u r doing it for Dialog Programming then it is some what different.. Do write me in such case...

One more FM is DATE_COMPUTE_DAY which gives u ans in int like 1, 2, 3 etc.

U can use

case

statement like

when '1'

write 😕 "Monday".

and so on..........

Hope this will work for U.

Do reward for me if u find it working.

former_member188685
Active Contributor
0 Kudos
398

Hi Yamini,

I think you got the Solution.

still you are not getting the correct day.

regards

vijay

please close this thread if your problem solves.

Former Member
0 Kudos
398

Hi,

Your input date format should be MMDDYYYY. After that you convert into internal format by using function module CONVERT_DATE_TO_INTERNAL. Here is the code.

&----


*& Report ZDATE

*&

&----


*&

*&

&----


REPORT ZDATE.

data: begin of itab occurs 0,

date1 like sy-datum,

day like DTRESR-WEEKDAY,

end of itab.

**--populating internal table with sample data

itab-date1 = '28112005'.

append itab.

itab-date1 = '29112005'.

append itab.

itab-date1 = '30112005'.

append itab.

loop at itab.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

DATE_EXTERNAL = itab-date1

  • ACCEPT_INITIAL_DATE =

IMPORTING

DATE_INTERNAL = itab-date1

  • EXCEPTIONS

  • DATE_EXTERNAL_IS_INVALID = 1

  • OTHERS = 2

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

modify itab.

endloop.

*---calling FM

loop at itab.

CALL FUNCTION 'DATE_TO_DAY'

EXPORTING

date = itab-date1

IMPORTING

WEEKDAY = itab-day.

modify itab.

endloop.

*-----outputting data

loop at itab.

write:/ itab-date1,itab-day.

endloop.

I have tested it, working fine.

Cheers

Rajavardhana Reddy

Former Member
0 Kudos
398

Hi All,

Thanks for all your valubale suggetions.

FM work fine with dd.mm.yyyy format.

There was no need to convert them into mm/dd/yyyy format

Regards

Yamini.A

Former Member
0 Kudos
398

Hi,

Use the below code before passing the value to the function module.

DATA : W_DATE LIKE SY-DATUM,

W_DATFM LIKE USR01-DATFM,

W_DAY(2) TYPE C,

W_MONTH(2) TYPE C,

W_YEAR(4) TYPE C,

W_LEN TYPE C.

W_LEN = STRLEN( DATUM ).

IF W_LEN = 8.

W_YEAR = DATUM+0(4).

W_MONTH = DATUM+4(2).

W_DAY = DATUM+6(2).

SELECT SINGLE DATFM INTO W_DATFM

FROM USR01

WHERE BNAME = SY-UNAME.

CASE W_DATFM.

WHEN 1.

CONCATENATE W_DAY W_MONTH W_YEAR INTO DATE SEPARATED BY '.'.

WHEN 2.

CONCATENATE W_MONTH W_DAY W_YEAR INTO DATE SEPARATED BY '/'.

WHEN 3.

CONCATENATE W_MONTH W_DAY W_YEAR INTO DATE SEPARATED BY '-'.

WHEN 4.

CONCATENATE W_YEAR W_MONTH W_DAY INTO DATE SEPARATED BY '.'.

WHEN 5.

CONCATENATE W_YEAR W_MONTH W_DAY INTO DATE SEPARATED BY '/'.

WHEN 6.

CONCATENATE W_YEAR W_MONTH W_DAY INTO DATE SEPARATED BY '-'.

ENDCASE.

ENDIF.

Now, pass DATE to the function module and the required output is fetched.