Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Date and Time Format With HH24

Hi
I have input Date coming with "18/APR/91 16:00:00" from oracle , I need to load the into Postgresql table
YEAR
MONTH
DATE
HOUR
each have separately column, and I'm using following method.

TalendDate.getPartOfDate("YEAR",row1.PSTART)
TalendDate.getPartOfDate("MONTH",row1.PSTART)
TalendDate.getPartOfDate("DAY_OF_MONTH",row1.PSTART)
TalendDate.getPartOfDate("HOUR",row1.PSTART)
Im getting following result
YEAR = 1991
MONTH = 3
DATE = 18
HOUR = 4
but we expecting result should be
YEAR = 1991
MONTH = 4
DATE = 18
HOUR = 16
Please let me know..
Thanks
Rajesh G
Labels (2)
19 Replies
Anonymous
Not applicable
Author

Hi Rajesh
The TalendDate.getPartOfDate() method calls java.util.Calendar to get return value.
For MONTH, Calendar class defines the return value of January is 0 while April is 3... You have to add 1 manually.
For HOUR, use 16%12.
Regards,
Pedro
Anonymous
Not applicable
Author

Thanks for Input..
Your mean to say I have use like this? What format can I use?

TalendDate.getPartOfDate("HOUR",row1.PSTART) %12

Please let me know?
Thanks
Rajesh G
Anonymous
Not applicable
Author

Hi
Yes. The expression is correct.
Regards,
Pedro
Anonymous
Not applicable
Author

Thanks..but Still I'm getting same result..
instead of 16 again Im getting HOUR = 4
please let me know any other format?
Thanks
Rajesh G
Anonymous
Not applicable
Author

Hi Rajesh
Sorry. My fault...
You'd better modify TalendDate.getPartOfDate() method as seen bellow.
  public static int getPartOfDate(String partName, Date date) {
if (partName == null || date == null)
return 0;
int ret = 0;
String[] fieldsName = { "YEAR", "MONTH", "HOUR", "MINUTE", "SECOND", "DAY_OF_WEEK", "DAY_OF_MONTH", "DAY_OF_YEAR",
"WEEK_OF_MONTH", "DAY_OF_WEEK_IN_MONTH", "WEEK_OF_YEAR", "TIMEZONE", "HOUR OF DAY" };
java.util.List<String> filedsList = java.util.Arrays.asList(fieldsName);
Calendar c = Calendar.getInstance();
c.setTime(date);
switch (filedsList.indexOf(partName)) {
case 0:
ret = c.get(Calendar.YEAR);
break;
case 1:
ret = c.get(Calendar.MONTH);
break;
case 2:
ret = c.get(Calendar.HOUR);
break;
case 3:
ret = c.get(Calendar.MINUTE);
break;
case 4:
ret = c.get(Calendar.SECOND);
break;
case 5:
ret = c.get(Calendar.DAY_OF_WEEK);
break;
case 6:
ret = c.get(Calendar.DAY_OF_MONTH);
break;
case 7:
ret = c.get(Calendar.DAY_OF_YEAR);
break;
case 8:
// the ordinal number of current week in a month (it means a 'week' may be not contain 7 days)
ret = c.get(Calendar.WEEK_OF_MONTH);
break;
case 9:
// 1-7 correspond to 1, 8-14 correspond to 2,...
ret = c.get(Calendar.DAY_OF_WEEK_IN_MONTH);
break;
case 10:
ret = c.get(Calendar.WEEK_OF_YEAR);
break;
case 11:
ret = (c.get(Calendar.ZONE_OFFSET)) / (1000 * 60 * 60);
break;
case 12:
ret = c.get(Calendar.HOUR_OF_DAY);
break;
default:
break;
}
return ret;
}

Then you can use expression TalendDate.getPartOfDate("HOUR OF DAY",row1.PSTART).
The return value is 16 this time.
Regards,
Pedro
Anonymous
Not applicable
Author

Thanks for your help its very helpful....
for TalendDate.getPartOfDate() this is SYSTEM Routine. How should edit and modify?
or Can I create my own Routine using same code?
Thanks
Rajesh G
Anonymous
Not applicable
Author

Hi Rajesh
Yes. You can create a custom routine using the code above.
Regards,
Pedro
Anonymous
Not applicable
Author

Thanks Pedro.
after creating custom routine and using DateFunction.getPartOfDate("HOUR_OF_DAY",row1.PSTART)
Im getting value instead of 16 HOUR = 0
If i use following method
DateFunction.getPartOfDate("HOUR_OF_DAY",row1.PSTART) = 0
DateFunction.getPartOfDate("HOUR",row1.PSTART) = 4
Im not sure the problem ?
Please let me know..
Anonymous
Not applicable
Author

Hi
I'm afraid you didn't create this custom routine correctly.
Don't forget to import these classes on the top of your routine.
import java.util.Calendar;
import java.util.Date;
And I have written an email and attached my custom routine.
Regards,
Pedro