calculate new date

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
ahmed7
User
Posts: 97

calculate new date

Post by ahmed7 »

Hello
I used asp.net make 2021 , and like to add number of days for initial date and extract the new date automatically.
there is any easy way to do that please?
will appreciate for any help.
Thanks


MichaelG
User
Posts: 1095

Post by MichaelG »

It should be something like:
Convert.ToDateTime(<dateTimeString>).AddDays(<day>).ToString(<format>)


ahmed7
User
Posts: 97

Post by ahmed7 »

actually its not working , even if I try the current date and put in new field not working too.


ahmed7
User
Posts: 97

Post by ahmed7 »

If you have any clear sample to da that please??


MichaelG
User
Posts: 1095

Post by MichaelG »

Show your actual codes.


ahmed7
User
Posts: 97

Post by ahmed7 »

something like this :
var days = $row["Period"].toNumber();
Convert.ToDateTime('Project_Start_Date').AddDays(days).ToString()
$row["Project_End_Date"].value(Project_Start_Date);

Period is the numbers of days which want to add
Project_Start_Date is first date
Project_End_Date is final date after add days


ahmed7
User
Posts: 97

Post by ahmed7 »

You can forget this code , any simple code with that information (started date , period days and end date (wanted))?
Thanks


MichaelG
User
Posts: 1095

Post by MichaelG »

If you are referring to client side script (JavaScript), it should be something like:

var days = $row["Period"].toNumber();
var dt = ew.formatDateTime($row["Project_Start_Date"].toDate().plus({ days: days }), ew.DATE_FORMAT);
$row["Project_End_Date"].value(dt);


ahmed7
User
Posts: 97

Post by ahmed7 »

yes I am you are referring to client side script , but still not working.
this code not work fine :
var dt = ew.formatDateTime($row["Project_Start_Date"].toDate().plus({ days: days }), ew.DATE_FORMAT);
i did try the others and were so good.


MichaelG
User
Posts: 1095

Post by MichaelG »

Press F12 -> Console to check if there is any JavaScript error. Add codes to show and debug the values. For example:

var days = ...;
console.log("days:" + days);
console.log("start date:" + $row["Project_Start_Date"]);
// etc...


ahmed7
User
Posts: 97

Post by ahmed7 »

I did check that , and found this :
(ew.formatDateTime) is not a function.


MichaelG
User
Posts: 1095

Post by MichaelG »

Sorry, the codes are for ASP.NET Maker 2022. For older version, try ew.formatDate


ahmed7
User
Posts: 97

Post by ahmed7 »

That's right , about the part (ew.formatDateTime) and no problem if I change this to (ew.formatDate)
but still another parts not a function : ($row["Project_Start_Date"].toDate().plus({ days: days }), ew.DATE_FORMAT);

Thanks


motfs
User
Posts: 258

Post by motfs »

Old version use moment. It should be something like:

var days = $row["Period"].toNumber();
var startDate = $row["Project_Start_Date"].val();
// console.log(startDate);
var endDate = ew.parseDate(startDate, ew.DATE_FORMAT.toUpperCase()).add({ days: 7 });
// console.log(endDate, ew.formatDate(endDate));
$row["Project_End_Date"].value(ew.formatDate(endDate));


ahmed7
User
Posts: 97

Post by ahmed7 »

Thank You so much , its work fine now


Post Reply