Topic
  • 2 replies
  • Latest Post - ‏2014-05-14T15:10:40Z by FadyRamzy
FadyRamzy
FadyRamzy
29 Posts

Pinned topic Trying to get next month from DateTimeLib but failed

‏2014-05-13T15:01:33Z |

Hello All,

This seems to be very simple but for some reason it fails with me

my requirement is very simple, i will read a date value from database and wants to get the start of next month for this date

i am trying to use the DateTimeLib

I appreciate if someone can consult me for this

=========================================

tempDate, nextMonth, currentMonth DATE;

function main()
tempDate = DateTimeLib.currentDate();
currentMonth = DateTimeLib.monthOf(tempDate);
nextMonth = currentMonth;
nextMonth = DateTimeLib.monthOf(currentMonth);
SysLib.writeStdout("tempDate = " + tempDate);
SysLib.writeStdout("currentMonth = " + currentMonth);
SysLib.writeStdout("nextMonth = " + nextMonth);
end

===========================

Ouput:

tempDate = 5/13/14
currentMonth = 1/5/00
nextMonth = 1/1/00
---------------------------------------

 

 

  • dan_darnell
    dan_darnell
    973 Posts

    Re: Trying to get next month from DateTimeLib but failed

    ‏2014-05-13T16:59:42Z  

    From the doc:

    DateTimeLib.monthOf: Returns a positive integer that represents a month, as derived from a variable of type TIMESTAMP.

    So maybe something like this:

    today date = DateTimeLib.currentDate();
    month int = DateTimeLib.monthOf(today) + 1;
    year int = DateTimeLib.yearOf(today);
    nextMonth date = DateTimeLib.mdy(month, 1, year);
    
    SysLib.writeStdout("Today = " + today);
    
    SysLib.writeStdout("Date value for first of next month = " + nextMonth);
       
    

    With the result:

    Today = 5/13/14
    Date value for first of next month = 6/1/14

    Is that what you need?

    Dan

     

  • FadyRamzy
    FadyRamzy
    29 Posts

    Re: Trying to get next month from DateTimeLib but failed

    ‏2014-05-14T15:10:40Z  

    From the doc:

    DateTimeLib.monthOf: Returns a positive integer that represents a month, as derived from a variable of type TIMESTAMP.

    So maybe something like this:

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">today date = DateTimeLib.currentDate(); month int = DateTimeLib.monthOf(today) + 1; year int = DateTimeLib.yearOf(today); nextMonth date = DateTimeLib.mdy(month, 1, year); SysLib.writeStdout("Today = " + today); SysLib.writeStdout("Date value for first of next month = " + nextMonth); </pre>

    With the result:

    Today = 5/13/14
    Date value for first of next month = 6/1/14

    Is that what you need?

    Dan

     

    Dan,

    Thank you very much, this is exactly what i need