Page 1 of 1

calculate new date

Posted: Tue Dec 27, 2022 11:12 pm
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


Re: calculate new date

Posted: Wed Dec 28, 2022 8:02 am
by MichaelG

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


Re: calculate new date

Posted: Fri Dec 30, 2022 12:23 am
by ahmed7

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


Re: calculate new date

Posted: Fri Dec 30, 2022 4:11 am
by ahmed7

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


Re: calculate new date

Posted: Fri Dec 30, 2022 6:42 am
by MichaelG

Show your actual codes.


Re: calculate new date

Posted: Fri Dec 30, 2022 6:56 am
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


Re: calculate new date

Posted: Fri Dec 30, 2022 9:57 pm
by ahmed7

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


Re: calculate new date

Posted: Sat Dec 31, 2022 6:25 am
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);


Re: calculate new date

Posted: Sat Dec 31, 2022 6:00 pm
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.


Re: calculate new date

Posted: Sun Jan 01, 2023 7:12 am
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...


Re: calculate new date

Posted: Sun Jan 01, 2023 2:56 pm
by ahmed7

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


Re: calculate new date

Posted: Mon Jan 02, 2023 6:23 am
by MichaelG

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


Re: calculate new date

Posted: Mon Jan 02, 2023 2:55 pm
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


Re: calculate new date

Posted: Tue Jan 03, 2023 8:10 am
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));


Re: calculate new date

Posted: Tue Jan 03, 2023 1:36 pm
by ahmed7

Thank You so much , its work fine now