sum months to date

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Dominik04
User
Posts: 24

sum months to date

Post by Dominik04 »

Good morning, I ask for another little help:
I have three fields:
start_date ---> date format
end_date ---> date format
months ---> number format

"start date" field (insert the date)
"month" field insert a numerical value (therefore the months);
"end date" field is the result of the start date + months.

in add page I would like to add the months to the start date, in javascript I try to do this:

{ // keys = event types, values = handler functions
"change keyup keydown keypress blur": function(e) {

var $row = $(this).fields();
var miadata = new Date ($row["start_date"].value());
var fine= miadata.getMonth() + 1;
$row["DATA_FINE"].value(fine);

}
}
I'm trying them all. I look for solutions in the forum, but I can not find anything.


arbei
User
Posts: 9396

Post by arbei »

Try:

var miadata = $row["start_date"].toJsDate(); // Get the input value as a JavaScript Date object

Also see the topic Server Events and Client Scripts > Startup Script, it explains the methods of the jQuery .fields() plugin.


Dominik04
User
Posts: 24

Post by Dominik04 »

I solved in this way:

{ // keys = event types, values = handler functions
"change keyup keydown keypress blur": function(e) {

var $row = $(this).fields();
var today = $row["START_DATE"].toJsDate();
var day= today.getDate();
var month= today.getMonth()+1;
var year= today.getFullYear();

var month=$row["month"].value()-1;

var d = new Date(year,month,day);
d.setMonth(d.getMonth()+month);

var future_day=d.getDate();
var future_month=d.getMonth()+1;
var future_year=d.getFullYear();
var dateA = future_day+ "/"+ future_month+"/"+future_year;
$row["DATA_FINE"].value(dateA);
}
}
it is not elegant as a code, it seems to me that you work well.


arbei
User
Posts: 9396

Post by arbei »

You can convert to Moment date by $row["start_date"].toDate() and use Moment method to add month, read https://momentjs.com/docs/#/manipulating/.


Dominik04
User
Posts: 24

Post by Dominik04 »

thanks a lot to everyone for the help, Arbei I followed your advice and it works great.


halexoliveira
User
Posts: 8

Post by halexoliveira »

Can you post the scrip here? Tks!


Post Reply