‎2007 May 29 9:04 AM
Hi all.
Dear friends, I have lost my notes on date format. I need your help.
When I read the date from the db, I am encountered with the format: 22052007; however I want it to be like 22.05.2007.
How can I seperate the 22 or 05 or 2007 from the whole??? and then concatenate them?
Thanks in advance.
Deniz.
‎2007 May 29 9:08 AM
data: date type sy-datum.
data: lv_month(2) type c,
lv_day(2) type c,
lv_year(4) type c.
date = sy-datum.
lv_day = date(2) .
lv_month = date(2)+2.
lv_year = date(4)+4.
‎2007 May 29 9:09 AM
Then you can concatenate like:
data: date1(10) type c.
concatenate lv_day lv_month lv_year into date1 seperated by ':'.
‎2007 May 29 9:08 AM
say v_date = '22052007'.
declare another variable of length 10
data : v_date1(10).
concatenate v_date0(2) v_date2(2) v_date+4(4) into v_date1 separated by '.'.
write : v_date1.
‎2007 May 29 9:09 AM
hi deniz,
u can use some string manipulation codes like SHIFT and MOVE to separate the month, day and year from the date format. see which one comes first second and last and u can separate easily with string manipulation.
thanks,
max
‎2007 May 29 9:10 AM
hi
You can use EDIT MASK Statement to solve this problem
Or else u can split into 3 parts and use cancatenate function.
for eg. date = 22052007.
date_d = date + 0(2) -> 22
date_m = date + 2(2) -> 05
date_y = date + 4(4) -> 2007.
concatenate date_d date_m date_y separated by '.'.
hope this will serve, please reward if you find it handy.
Regards,
Ravi
‎2007 May 29 9:10 AM
Hi Deniz,
You may use offset.
let say your dbdate = 22052007.
concatenate dbdate(2) '.' dbdate2(2) '.' dbdate4(4) into var.
var should be 22.05.2007.
‎2007 May 29 9:10 AM
are you sure you are getting 22052007 instead of 20070522 because by default date format is yyyymmdd. so if you are getting yyyymmdd format do like this
data : v_date(10).
concatenate sy-datum6(2) sy-datum4(2) sy-datum+0(4) into v_date separated by '.'.
write : / date.
or you can use edit mask in write statement '__.__.____'.
regards
shiba dutta
‎2007 May 29 9:13 AM
See the problem in these date formats is that always make sure you have the date converted to YYYYMMDD format .
use Fm Convert_date_to_internal .
to make the Db date format of urs into sap standard YYYYMMDD
data : x(10).
then use the offset as
concatenate date4(2) date6(2) date+0(4) into field X separated by '.' .
Regards,
Vijay
‎2007 May 29 9:17 AM
Use FM DATE_STRING_CONVERT
Import to FM : date format and date string
Export from FM : result date
‎2007 May 29 9:19 AM
* Using the WRITE statement
***************************
data: gd_date(10). "field to store output date
* Converts SAP date from 20020901 to 01.09.2002
write sy-datum to gd_date dd/mm/yyyy.
* Converts SAP date from 20020901 to 01.09.02
write sy-datum to gd_date dd/mm/yy.
* Using data manipulation techniques
************************************
data: gd_date(8). "field to store output date
* Converts SAP date from 20010901 to 01092001
gd_date(2) = sy-datum+6(2).
gd_date+2(2) = sy-datum+4(2).
gd_date+4(4) = sy-datum(4).
* Using Function modules
************************
data: gd_date(8). "field to store output date
* Converts date from 20010901 to 01SEP2001
gd_date = sy-datum.
CALL FUNCTION 'CONVERSION_EXIT_IDATE_OUTPUT'
EXPORTING
input = gd_date
IMPORTING
OUTPUT = gd_date.
girish