cancel
Showing results for 
Search instead for 
Did you mean: 

Julian date to calendar date UDF

Former Member
0 Kudos

Hi java gurus,

Can someone write below abap code into UDF.

This is to convert julian date(2011348) to calendar date(12/13/2011)

-


ABAP code for Julian date conversion

_________________________________________

DATA: jdate(7) VALUE '2011348',

gdate TYPE sy-datum,

days TYPE i.

CONCATENATE jdate(4) '0101' INTO gdate.

days = jdate+4(3).

gdate = gdate + days.

____________________________________________

ty.

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor

Hi,

You can try with standard date function "TransformDate".

In the function set parameters as below

please use format of source date as: yyyyD

and target format as : MM/dd/yyyy

I feel there is no need of an UDF.

Regards

Anupam

baskar_gopalakrishnan2
Active Contributor
0 Kudos

DateTrans Standard function will cover this feature. You dont really need to for UDF on this. Provide input what you get and specify output how you want.

Former Member
0 Kudos

Thanks guys.

it worked well with standard function.

also, another UDF for future references on this post,

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, Integer.parseInt(Integer.toString(calendar.get(Calendar.YEAR)).substring(0, 2)+inpdate.substring(0, 2)));
calendar.set(Calendar.DAY_OF_YEAR, Integer.parseInt(inpdate.substring(inpdate.length() - 3, inpdate.length())));
SimpleDateFormat simpDate = new SimpleDateFormat("ddMMyy");
return simpDate.format(calendar.getTime());

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi. Santosh

Tyr this simple UDF.


            String val = "2011348";
            Date myDate = new SimpleDateFormat("yyyyD").parse(val);            
            SimpleDateFormat sdf= new java.text.SimpleDateFormat("MM/dd/yyyy");
            String fecha = sdf.format(myDate);
            return fecha;

Former Member
0 Kudos

Thank you luis,

could you please wrap it in a code, that i can test in eclipse 3.1.

i tried doing it, but ended with errors.

-

Former Member
0 Kudos

Hi. Try this

Don't forget to add the reference.

import java.util.Date;

import java.text.SimpleDateFormat;



       String fecha ="";
        try {
            String val = "2011348";
            Date myDate = new SimpleDateFormat("yyyyD").parse(val);
            SimpleDateFormat sdf= new java.text.SimpleDateFormat("MM/dd/yyyy");
            fecha = sdf.format(myDate);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return fecha;