Skip to Content

I have seen in many Re: Changing the date format where month is a string where people ask about several Re: Regarding converting date fucntion(UDF) and in most of the cases people have suggested to go for UDF to get the desired date format. I hope this blog will be very useful for beginners. Here in this blog I will show few date formats conversions which are possible via standard DateTrans function.                                                                            

Case 1:

How to get the “Month Name” from given Date by using DateTrans function.

Let’s say we have incoming date as 2009/02/13 and we want to get the desired output as 2009-FEB-13.

To get the above result you don’t need to write any UDF, it is simply possible with standard DateTrans function. Open the DateTrans function and double click and then enter yyyy/MM/dd in the “Format of Source Date” and enter  yyyy-MMM-dd in the “Target Format” as shown in below picture.
 
image
Here is the results from display Queue. 
image

Case 2:

How to get the “Date” from give “Year and Days” by using DateTrans function.

Let’s say you have your source date in the from of year & days only i.e. yyddd and you want to convert it into yyyy-MM-dd or any other format.

Open the DateTrans function and then enter yyddd in the “Format of Source Date” and enter  yyyy-MM-dd in the “Target Format”. You can chose any other target format as per your need.  
 
image

The result after mapping are as shown below.

image 

Case 3:

How to get time stamp with mili seconds.

image 

Case 4: 

How to get “Week Number” from given date Or how to get the “Date” from given Year and Week.

Just do exactly same as shown in the below picture.

image 

Case 5:

Calculate Date in future or past.

For this, we have to use the UDF as shown below. You just need to map a constant value to this UDF to calculate the future or past date.

UDF Picture:

 

UDF Code:

 

 Mapping & Test Results:

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

    1. Sarvesh Singh Post author
      Well not the whole blog but some part of it says same thing (Exmp 1). In my opinion If we  have something new then I think there is no harm to learn it. 🙂

      Regards,
      Sarvesh

      (0) 
  1. Puneet Singhal
    Sarvesh,
    Indeed its a helpful blog but I dont think output of point 5 will be correct in your example…just run it with input (1999/03/01) and the reason being you can operate arithematic functions on date as it has to follow calender 🙂 .

    Actually, we will have to use GregorianCalendar java class to achieve that kind of requirement.

    Something like this will help:
    public String addDate(String dt, int addd, Container container) throws StreamTransformationException{
    try
    {
         Date dat = new SimpleDateFormat(“yyyyMMdd”).parse(dt);
         Calendar cal = new GregorianCalendar();
         cal.setTime(dat);
         cal.add(Calendar.DAY_OF_MONTH, + addd);
         Date bar = cal.getTime();
         String expDate = new SimpleDateFormat(“yyyyMMdd”).format(bar);
    return (expDate);
    }
    catch(Exception ex)
    {
         return (dt);
    }

    }

    (0) 

Leave a Reply