• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » How to take a day from a date as a string and month to ?

#1 2008-11-10 09:11:00

ead
Member
Registered: 2008-11-05
Posts: 30

How to take a day from a date as a string and month to ?

Hi
I have a "date" cell in my table.
I want to take the day in the week from it as a string - means "sunday, monday,..."
And not as a number.
How can it be done?

And the same goes for the month (January and so on)

Offline

#2 2008-11-10 09:48:01

cahsohtoa
Member
Company: AEFE
Registered: 2008-02-19
Posts: 261
Website

Re: How to take a day from a date as a string and month to ?

you can use this routine

public static String getDaysOfWeek(java.util.Date myDate) {

        String theDay="";
        String [] allDays = {"","SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"};
       
        java.util.Calendar cal1 = java.util.Calendar.getInstance();
        cal1.setTime(myDate);
       
        theDay=allDays[cal1.get(java.util.Calendar.DAY_OF_WEEK)];
       
         
        return theDay;
         }

Offline

#3 2008-11-10 09:50:49

ead
Member
Registered: 2008-11-05
Posts: 30

Re: How to take a day from a date as a string and month to ?

oh, and where to put it so I can use it with my tMap object ??

Offline

#4 2008-11-10 10:09:42

cahsohtoa
Member
Company: AEFE
Registered: 2008-02-19
Posts: 261
Website

Re: How to take a day from a date as a string and month to ?

you can create a routine in  Repository>Code>Routine for exemple MyRoutine and copy/paste

public static String getDaysOfWeek(java.util.Date myDate) {

        String theDay="";
        String [] allDays = {"","SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"};
       
        java.util.Calendar cal1 = java.util.Calendar.getInstance();
        cal1.setTime(myDate);
       
        theDay=allDays[cal1.get(java.util.Calendar.DAY_OF_WEEK)];
       
         
        return theDay;
         }

in place of

    public static void helloExample(String message) {
        if (message == null) {
            message = "World";
        }
        System.out.println("Hello " + message + " !");
    }

In your tMap

you can use it in a field using MyRoutine.getDaysOfWeek(row1.mydate)

Offline

#5 2008-11-10 10:19:21

ead
Member
Registered: 2008-11-05
Posts: 30

Re: How to take a day from a date as a string and month to ?

Thanks!
Work like a charm,
I guess the same thing goes for month?
public static String getMonth(java.util.Date myDate) {

        String theMonth="";
        String [] allMonths = {"","JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY", "AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
       
        java.util.Calendar cal1 = java.util.Calendar.getInstance();
        cal1.setTime(myDate);
       
        theMonth=allMonths[cal1.get(java.util.Calendar.MONTH_OF_THE_YEAR)];
       
         
        return theMonth;
         }

Last edited by ead (2008-11-10 10:20:03)

Offline

#6 2008-11-10 10:26:45

cahsohtoa
Member
Company: AEFE
Registered: 2008-02-19
Posts: 261
Website

Re: How to take a day from a date as a string and month to ?

yes It will work fine

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » How to take a day from a date as a string and month to ?

Board footer

Powered by FluxBB