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: 

Date format

Former Member
0 Kudos

Hi all,

I want to convert date which is in the format MMDDYY to sy-datum format YYYYMMDD.how can i do this?

Thanks,

Rakesh.

7 REPLIES 7

Former Member
0 Kudos

use

DATA: V_DATE LIKE SY-DATUM,

V_DATE2(10).

CALL FUNCTION 'CONVERT_DATE_INPUT'

EXPORTING

INPUT = '21102002' "DD.MM.YYYY

PLAUSIBILITY_CHECK = 'X'

IMPORTING

OUTPUT = V_DATE "YYYY.MM.DD

EXCEPTIONS

PLAUSIBILITY_CHECK_FAILED = 1

WRONG_FORMAT_IN_INPUT = 2

OTHERS = 3.

V_DATE2 = V_DATE.

WRITE:/ V_DATE2.

Rewards if useful

Former Member
0 Kudos

Hi Rakesh,

Use FM <b>CONVERT_DATE_TO_INTERNAL</b>

Regards

Aneesh.

Former Member
0 Kudos
data : V_date1(6) value '072307',
          v_date2(8).

concatenate sy-datum+0(2) v_date1+4(2) v_date1+0(2) v_date1+2(2) into v_date2.

write : v_date2.

Former Member
0 Kudos

CONVERT_DATE_TO_EXTERNAL.

CONVERT_DATE_TO_INTERNAL.

DATE_STRING_CONVERT

Function Modules related to Date and Time Calculations

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

MONTHS_BETWEEN_TWO_DATES : To get the number of months between the two dates.

END_OF_MONTH_DETERMINE_2 : Determines the End of a Month.

HR_HK_DIFF_BT_2_DATES : Find the difference between two dates in years, months and days.

FIMA_DAYS_AND_MONTHS_AND_YEARS : Find the difference between two dates in years, months and days.

MONTH_NAMES_GET : Get the names of the month

WEEK_GET_FIRST_DAY : Get the first day of the week

HRGPBS_HESA_DATE_FORMAT : Format the date in dd/mm/yyyy format

SD_CALC_DURATION_FROM_DATETIME : Find the difference between two date/time and report the difference in hours

L_MC_TIME_DIFFERENCE : Find the time difference between two date/time

HR_99S_INTERVAL_BETWEEN_DATES : Difference between two dates in days, weeks, months

LAST_DAY_OF_MONTHS : Returns the last day of the month

or

simple use:

WRITE date to ext_date MMDDYYYY.

date is in YYYYMMDD for mat type d

and ext_date(8) type c

or

data: l_date(10) type c.

write: sy-datum to date.

write : date.

regards,

srinivas

<b>

*rewards for useful answers* </b>

former_member235056
Active Contributor
0 Kudos

Hi,

Use FM,

CONVERT_DATE_TO_EXTERNAL - Converts date from system storage format to users specified display format.

report z-alv_a_sixpence. 

include z_alv_include. 

*** Internal Tables 
*** Selection Screen 

*** Parameter for the user to choose how the initial screen will be (vital 
*** for running big reports in background) 
SELECTION-SCREEN BEGIN OF BLOCK blk3 WITH FRAME TITLE text-003. 
PARAMETERS: p_vari LIKE disvariant-variant. 
SELECTION-SCREEN END OF BLOCK blk3. 

*** At Selection-Screen have a word with the display variant 
AT SELECTION-SCREEN. 
PERFORM check_variant. 

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari. 
PERFORM f4_for_variant. 

START-OF-SELECTION. 
END-OF-SELECTION. 

******* Build Field Catalogs (Begin)************************** 
PERFORM resetvalues. 
fieldcat_ln-key = 'X'. 
fieldcat_ln-hotspot = 'X'. 

PERFORM addfield USING '2' 'LIKP' 'WERKS'. "Plant 

PERFORM build_sortcat. 
*******Build Field Catalogs (End)****************************** 

*******Build Event Catalog (Begin)***************************** 
PERFORM build_eventcat. 
PERFORM build_layout. 
********Add a header at the top of the report ******* 
PERFORM set_report_header USING w_list_top_of_page[]. 
********Start List Viewer 
PERFORM start_list_viewer. 
*******Start List Viewer (End)********************************* 

********Process Call Back Events (Begin)*************************** 

FORM user_command USING ucomm LIKE sy-ucomm 
selfield TYPE slis_selfield. 
CASE ucomm. 
WHEN '&IC1'. 
READ TABLE irepo INDEX selfield-tabindex. 
CHECK sy-subrc = 0. 

CASE selfield-sel_tab_field. 
WHEN 'IREPO-VBELN'. 
SET PARAMETER ID 'VL' FIELD irepo-vbeln. 
CALL TRANSACTION 'VL03' AND SKIP FIRST SCREEN. "Display Outbound Delivery 
ENDCASE. 
WHEN '&TMP'. "Button with the 'refresh' icon on self defined status 

ZSTANDARD 
*** We are going to refresh the display so tell the ALV this 
selfield-refresh = 'X'. 
*** Off we go! 
PERFORM refresh. 
ENDCASE. 
ENDFORM. 

********Process Call Back Events (End)****************************** 

INCLUDE Z_ALV_INCLUDE . 
********Declare Data Areas for List Viewer (Begin)************ 

TYPE-POOLS: SLIS. 

DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, 
FIELDCAT_LN LIKE LINE OF FIELDCAT, 
SORTCAT TYPE SLIS_T_SORTINFO_ALV, 
SORTCAT_LN LIKE LINE OF SORTCAT, 
EVENTCAT TYPE SLIS_T_EVENT, 
EVENTCAT_LN LIKE LINE OF EVENTCAT, 
LAYOUT TYPE SLIS_LAYOUT_ALV, 
C_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE', 
W_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER. 

DATA: COL_POS TYPE I, 
REPID LIKE SY-REPID, 
VARIANTE LIKE DISVARIANT, 
DEF_VARIANTE LIKE DISVARIANT, 
VARIANT_EXIT(1) TYPE C, 
VARIANT_SAVE(1) TYPE C, 
VARIANT_DEF(1) TYPE C, 
P_LIGNAM TYPE SLIS_FIELDNAME VALUE 'TRAFFIC_LIGHTS', 
W_DATUM(10) TYPE C. "Convert system Date for Output 

*******Declare Data Areas for List Viewer (End)*************** 

*********FORM ROUTINES (Begin)********************************* 

*** Start Values for ALV Field Catalouge 
FORM RESETVALUES. 
FIELDCAT_LN-KEY = SPACE. 
FIELDCAT_LN-DO_SUM = SPACE. 
FIELDCAT_LN-NO_OUT = SPACE. 
FIELDCAT_LN-QFIELDNAME = SPACE. 
FIELDCAT_LN-HOTSPOT = SPACE. 
FIELDCAT_LN-OUTPUTLEN = '0'. 

CLEAR: FIELDCAT_LN-SELTEXT_L, FIELDCAT_LN-SELTEXT_M, 
FIELDCAT_LN-SELTEXT_S, FIELDCAT_LN-REPTEXT_DDIC. 
ENDFORM. 

*** Change key values for additional fields 
FORM ADDFIELD USING POSITION TABLE_VALUE FIELD_VALUE. 
FIELDCAT_LN-REF_TABNAME = TABLE_VALUE . 
FIELDCAT_LN-FIELDNAME = FIELD_VALUE. 
FIELDCAT_LN-COL_POS = POSITION. 
APPEND FIELDCAT_LN TO FIELDCAT. 
PERFORM RESETVALUES. 
ENDFORM. 

*** Same but for hidden fields 
FORM HIDFIELD USING POSITION TABLE_VALUE FIELD_VALUE. 
FIELDCAT_LN-NO_OUT = 'X'. 
FIELDCAT_LN-REF_TABNAME = TABLE_VALUE . 
FIELDCAT_LN-FIELDNAME = FIELD_VALUE. 
FIELDCAT_LN-COL_POS = POSITION. 
APPEND FIELDCAT_LN TO FIELDCAT. 
PERFORM RESETVALUES. 
ENDFORM. 

*** For changing the display names of fields in the internal table 
*** e.g. you might want to change LFA1-NAME1 from 'Name' to 'Vendor' 
FORM NEWNAME USING NAME. 
FIELDCAT_LN-SELTEXT_L = NAME.. 
FIELDCAT_LN-SELTEXT_M = NAME. 
FIELDCAT_LN-SELTEXT_S = NAME. 
FIELDCAT_LN-REPTEXT_DDIC = NAME. 
FIELDCAT_LN-OUTPUTLEN = '10'. 
ENDFORM. 

FORM BUILD_EVENTCAT. 
EVENTCAT_LN-NAME = C_TOP_OF_PAGE. 
EVENTCAT_LN-FORM = C_TOP_OF_PAGE. 
APPEND EVENTCAT_LN TO EVENTCAT. 
ENDFORM. " BUILD_EVENTCAT 

*** Add an extra button the user can press to 
*** see what selection criteria they entered 
*** This info will then appear when the report is printed 
FORM BUILD_LAYOUT. 
LAYOUT-GET_SELINFOS = 'X'. 
*** Time for fun with Traffic Lights 
*** The next lines says what field in the internal table we will Use 
*** to store the traffic light colour. It has to be type c, although 
*** the values can only be numeric. Typical SAP. 
LAYOUT-LIGHTS_FIELDNAME = P_LIGNAM. 
ENDFORM. 

FORM START_LIST_VIEWER USING ITAB TYPE TABLE 
VARIANT_AUTHORITY. 
DATA: PGM LIKE SY-REPID. 
PGM = SY-REPID. 

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY' 
EXPORTING 
*** What is the name of the program where the callback routine lives? 
I_CALLBACK_PROGRAM = PGM 
*** What is the FORM name that decides what status (toolbar) to use? 
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS' 
*** What is the FORM name that processes user input e.g. double clicks? 
I_CALLBACK_USER_COMMAND = 'USER_COMMAND' 
*** What are the settings for fancy tricks like traffic lights or 
*** automatically optimising column widths? 
IS_LAYOUT = LAYOUT 
*** What are the contents of the columns? 
IT_FIELDCAT = FIELDCAT 
*** How are they to be sorted and sub-totalled initially? 
IT_SORT = SORTCAT 
*** What sort of variants can the user save? 
*** A = Global or User Specific 
*** U = User Specific only 
I_SAVE = VARIANT_AUTHORITY 
*** Can we start off with a display variant the user chooses on the 
*** selection screen? 
IS_VARIANT = VARIANTE 
*** Settings for headers at the top of the screen 
IT_EVENTS = EVENTCAT[] 
*** What internal table are we using to generate the report? 
TABLES 
T_OUTTAB = ITAB 
EXCEPTIONS 
PROGRAM_ERROR = 1 
OTHERS = 2. 

ENDFORM. 

*** Form to call Menu with extra button 
FORM SET_PF_STATUS USING EXTAB TYPE SLIS_T_EXTAB. 
SET PF-STATUS 'ZSTANDARD' EXCLUDING EXTAB. 
ENDFORM. 

*** Routine to print out user at the top 
FORM SET_REPORT_HEADER USING LT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER 
NAME_OF_REPORT. 

DATA: LS_LINE TYPE SLIS_LISTHEADER. 

PERFORM CONVERT_DATE. 

CLEAR LS_LINE. 
LS_LINE-TYP = 'H'. 
LS_LINE-INFO = NAME_OF_REPORT. 
APPEND LS_LINE TO LT_TOP_OF_PAGE. 

CLEAR LS_LINE. 
LS_LINE-TYP = 'S'. 
LS_LINE-KEY = 'Run On :'. 
LS_LINE-INFO = W_DATUM. 
APPEND LS_LINE TO LT_TOP_OF_PAGE. 

LS_LINE-KEY = 'User Name :'. 
LS_LINE-INFO = SY-UNAME. 
APPEND LS_LINE TO LT_TOP_OF_PAGE. 

ENDFORM. " SET_REPORT_HEADER 

*** Routine to convert the system date into the format the outside 
*** world likes to see 
FORM CONVERT_DATE. 
<b>CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL' 
EXPORTING 
DATE_INTERNAL = SY-DATUM 
IMPORTING 
DATE_EXTERNAL = W_DATUM.</b> 
ENDFORM. " CONVERT_DATE 

FORM TOP_OF_PAGE. 

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' 
EXPORTING 
IT_LIST_COMMENTARY = W_LIST_TOP_OF_PAGE. 

ENDFORM. "TOP_OF_PAGE 

*** Code for looking up a variant 
FORM F4_FOR_VARIANT. 

CLEAR VARIANTE. 
VARIANTE-REPORT = SY-REPID. 

CALL FUNCTION 'REUSE_ALV_VARIANT_F4' 
EXPORTING 
IS_VARIANT = VARIANTE 
*** We want to see both user specific and global variants 
I_SAVE = 'A' 
IMPORTING 
E_EXIT = VARIANT_EXIT 
ES_VARIANT = DEF_VARIANTE 
EXCEPTIONS 
NOT_FOUND = 2. 

IF SY-SUBRC = 2. 
MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO 
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. 
ELSE. 
IF VARIANT_EXIT = SPACE. 
P_VARI = DEF_VARIANTE-VARIANT. 
ENDIF. 
ENDIF. 


ENDFORM. " F4_FOR_VARIANT 

*** For checking a variant is valid 
FORM CHECK_VARIANT. 

IF NOT P_VARI IS INITIAL. 
MOVE VARIANTE TO DEF_VARIANTE. 
MOVE SY-REPID TO DEF_VARIANTE-REPORT. 
MOVE P_VARI TO DEF_VARIANTE-VARIANT. 
MOVE SY-UNAME TO DEF_VARIANTE-USERNAME. 
VARIANT_SAVE = 'A'. 
CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE' 
EXPORTING 
I_SAVE = VARIANT_SAVE 
CHANGING 
CS_VARIANT = DEF_VARIANTE. 
VARIANTE = DEF_VARIANTE. 
ELSE. 
CLEAR VARIANTE. 
VARIANTE-REPORT = REPID. 
ENDIF. 

ENDFORM. 

***********FORM ROUTINES (END)**************************************

Pls reward all helpful points.

Regards,

Ameet

Former Member
0 Kudos

Hi,

Try with this code:

DATA: ZTEMP(9),zdd(2),zmmm(3),zyyyy(4),zfinal(12), v_date like sy-datum.

CLEAR: ZTEMP, ZDD, ZMMM, ZYYYY.

v_date = '072307'. "mm/dd/yy

zmmm = v_date+0(2).

zdd = v_date+2(2).

zyyyy = v_date+4(2).

concatenate '20' zyyyy into zyyyy.

concatenate zdd '.' zmmm '.' zyyyy into zfinal.

write:/ zfinal.

write:/ sy-datum. " here in my system sy-datum format is: dd.mm.yyyy

Regards,

Bhaskar

Former Member
0 Kudos

Dear Rakesh

If solved your problem please rewards any useful answers and close this.