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: 

How to find out day or year for particular date

Former Member
0 Kudos
3,750

Dear Sap Guru's,

IS it possible to find out day ,month or year for particular Date.Is their any function module available. please if u know ans immediately.

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos
702

Day = date+6(2)

Month = date+4(2)

Year = date+0(4).

Use FM DATE_TO_DAY to get the Day of the week e.g. Monday.

Regards,

Naimesh Patel

10 REPLIES 10

naimesh_patel
Active Contributor
0 Kudos
703

Day = date+6(2)

Month = date+4(2)

Year = date+0(4).

Use FM DATE_TO_DAY to get the Day of the week e.g. Monday.

Regards,

Naimesh Patel

raymond_giuseppi
Active Contributor
0 Kudos
702

Just use

- year = date+0(4).

- month = date4(2). " look also at [name of month|https://www.sdn.sap.com/irj/sdn/advancedsearch?query=nameof+month&cat=sdn_all]

- day = date6(2)." look also at [day of week|https://www.sdn.sap.com/irj/sdn/advancedsearch?query=dayof+week&cat=sdn_all]

Regards

Former Member
0 Kudos
702

hi

use this

DATE_TO_DAY : Returns the Day for the entered date.

MONTH_NAMES_GET : Get the names of the month

Check for this sample code

data: w_date like sy-datum,
      w_day  like DTRESR-WEEKDAY .

data:
    t_months like table of T247 with header line .


parameters: p_date like sy-datum.

* Geting day
CALL FUNCTION 'DATE_TO_DAY'
  EXPORTING
    date          = p_date
 IMPORTING
   WEEKDAY       = w_day.

  
* Geting month

   CALL FUNCTION 'MONTH_NAMES_GET'
    EXPORTING
      LANGUAGE                    = sy-langu
*    IMPORTING
*      RETURN_CODE                 =
     TABLES
       month_names                 = t_months
*    EXCEPTIONS
*      MONTH_NAMES_NOT_FOUND       = 1
*      OTHERS                      = 2
.

read table t_months with key MNR = p_date+2(2).

if sy-subrc = 0.
  write:/ w_day.
  write:/ t_months-KTX.   " short text.
  write:/ t_months-LTX.   " long text.

endif.

Cheers

Snehi

Edited by: snehi chouhan on Aug 11, 2008 4:23 PM

Former Member
0 Kudos
702

Hi,

To find out Day-use FM- DATE_TO_DAY

Regards,

Sujit

0 Kudos
702

Hi

try to use- 'DAY_ATTRIBUTES_GET'

BR

Lavanya

former_member705122
Active Contributor
0 Kudos
702

Hi,

Check this sample code,

DATA: 
  w_year(4)  TYPE c,
  w_month(2) TYPE c,
  w_day(2)   TYPE c.


day   = sy-datum+0(2).
month = sy-datum+2(2).
year  = sy-datum+4(4).

WRITE:/ day, month, year.

DATA:
  w_date     TYPE dats,
  w_date1    TYPE sy-datum,
  w_day(2)   TYPE c,
  w_month(2) TYPE c,
  w_year(4)  TYPE c,

  day(10)    TYPE c,
  month      LIKE  t247-ltx.
*  year(30)   TYPE c.
DATA:
  y_day(2)   TYPE  c,
  y_month(2) TYPE  c,
  y_year(4)  TYPE  c,
  y_stext    LIKE  t247-ktx,
  y_ltext    LIKE  t247-ltx,
  y_userdate(10) TYPE  c.

DATA:
  year       LIKE spell.

w_date = '20080201'.
w_date1 = w_date.

CALL FUNCTION 'DATE_TO_DAY'
  EXPORTING
    date    = w_date1
  IMPORTING
    weekday = day.


CALL FUNCTION 'HR_IN_GET_DATE_COMPONENTS'
  EXPORTING
    idate    = w_date1
  IMPORTING
    day      = y_day
    month    = y_month
    year     = y_year
    stext    = y_stext
    ltext    = month
    userdate = y_userdate.

w_day   = w_date+6(2).
w_month = w_date+4(2).
w_year  = w_date+0(4).

CALL FUNCTION 'SPELL_AMOUNT'
 EXPORTING
   amount          = w_year
   language        = sy-langu
 IMPORTING
   in_words        = year.

WRITE: / day, month, year-word.

Regards

Adil

Edited by: Syed Abdul Adil on Aug 11, 2008 5:44 PM

Former Member
0 Kudos
702

hi,

i think this may be useful to u.

FM DATE_TO_DAY

FM CACS_DATE_GET_YEAR_MONTH

Rgds.,

subash

former_member188685
Active Contributor
0 Kudos
702

Function module.

HR_IN_GET_DATE_COMPONENTS

Sample output.
 Import parameters               Value

 IDATE                           2008-01-01 "SY-datum value


 Export parameters               Value

 DAY                             01
 MONTH                           01
 YEAR                            2008
 STEXT                           JAN
 LTEXT                           January
 USERDATE                        2008-01-01

Former Member
0 Kudos
702

hiii

you can simply use offset for getting year and month from date...and for getting day use FM ISP_GET_WEEKDAY_NAME

just use date as import parameter

DATE 20080808 -->DATE

LANGUAGE E -->Language

WEEKDAY_NUMBER

will give you result as

LANGU_BACK E

LONGTEXT Friday

SHORTTEXT

regards

twinkal

Former Member
0 Kudos
702

CALCULATE_DATE: Calculates the future date based on the input.

DATE_TO_DAY: Returns the Day for the entered date.

DATE_COMPUTE_DAY: Returns weekday for a date

DATE_GET_WEEK: Returns week for a date

DAY_ATTRIBUTES_GET: Returns attributes for a range of dates specified

If you want the number only then

sy-datum+0(4) gives you the year

sy-datum+4(2) gives you the month

sy-datum+6(2) gives the date

Hope this helps!