
Anonymous
Not applicable
2014-06-20
11:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[resolved] Get last and first day of previous month using TalendDate.getDate
Hi there,
Me again.
How can I get the last and first day of the previous month using TalendDate.getDate? I've searched hi and lo and cannot find any suggestions.
This is very easy to do in sql using dateadd and datediff on the current date but I don't know if this is possible with Talend.
Thanks
Me again.
How can I get the last and first day of the previous month using TalendDate.getDate? I've searched hi and lo and cannot find any suggestions.
This is very easy to do in sql using dateadd and datediff on the current date but I don't know if this is possible with Talend.
Thanks
1,431 Views
1 Solution
Accepted Solutions

Anonymous
Not applicable
2014-06-20
12:02 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
This is also very easy in Talend with built-in functions: TalendDate.getFirstDayOfMonth(Date date) and TalendDate.getLastDayOfMonth(Date date), for example:
on tJava:
//TalendDate.getCurrentDate() returns the current date.
//TalendDate.addDate(TalendDate.getCurrentDate(),"-1","MM") returns last month.
java.util.Date firstDay=TalendDate.getFirstDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(),"-1","MM"));
Shong
This is also very easy in Talend with built-in functions: TalendDate.getFirstDayOfMonth(Date date) and TalendDate.getLastDayOfMonth(Date date), for example:
on tJava:
//TalendDate.getCurrentDate() returns the current date.
//TalendDate.addDate(TalendDate.getCurrentDate(),"-1","MM") returns last month.
java.util.Date firstDay=TalendDate.getFirstDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(),"-1","MM"));
Shong
1,431 Views
3 Replies

Anonymous
Not applicable
2014-06-20
12:02 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
This is also very easy in Talend with built-in functions: TalendDate.getFirstDayOfMonth(Date date) and TalendDate.getLastDayOfMonth(Date date), for example:
on tJava:
//TalendDate.getCurrentDate() returns the current date.
//TalendDate.addDate(TalendDate.getCurrentDate(),"-1","MM") returns last month.
java.util.Date firstDay=TalendDate.getFirstDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(),"-1","MM"));
Shong
This is also very easy in Talend with built-in functions: TalendDate.getFirstDayOfMonth(Date date) and TalendDate.getLastDayOfMonth(Date date), for example:
on tJava:
//TalendDate.getCurrentDate() returns the current date.
//TalendDate.addDate(TalendDate.getCurrentDate(),"-1","MM") returns last month.
java.util.Date firstDay=TalendDate.getFirstDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(),"-1","MM"));
Shong
1,432 Views

Anonymous
Not applicable
2014-06-23
01:52 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Shong!
Although there was one slight typo in your solution I had to remove the double quotes around the -1 as it was giving a string error.
Also, I added a second line to assign it to a context variable that I need to use later on.
java.util.Date firstDay=TalendDate.getFirstDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(),-1,"MM"));
context.start_date=TalendDate.formatDate("dd-MM-yyyy",firstDay);
Although there was one slight typo in your solution I had to remove the double quotes around the -1 as it was giving a string error.
Also, I added a second line to assign it to a context variable that I need to use later on.
java.util.Date firstDay=TalendDate.getFirstDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(),-1,"MM"));
context.start_date=TalendDate.formatDate("dd-MM-yyyy",firstDay);
1,431 Views

Anonymous
Not applicable
2015-08-20
08:09 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This discussion has helped me lot. Thanks to Shong and Facoda.
1,431 Views
