Page 1 of 1

Date calculation

Posted: 2019-07-28 06:36
by Moh Youba
Hello

Please I need help with date calculation. I want to calculate date from duration.

Date of start : 1/1/2000
Duration : 2 (from field)
End of training = date of start + duration (1/1/2002)

Thank you

Re: Date calculation

Posted: 2019-07-28 07:57
by pbottcher
Hi,
is your question to increase the year count by the duration?
And where do you want to do the calculation, in the front-end (via JS), on the server side (via PHP) or on the DB side (via SQL)?

Re: Date calculation

Posted: 2019-07-28 08:09
by Moh Youba
Hello
I want to display via JS in the front-end, in the table view
Thank you

Re: Date calculation

Posted: 2019-07-28 08:13
by Moh Youba
I try with something like this but do not work !!!

$j(function(){
$j('#dateOfStart').prop('readonly' , true);

$j('#dateOfStar-dd, #dateOfStar-mm, #dateOfStar').change(function(){
var dos = get_date('dateOfStare');
var today = new Date();
var duration= Math.abs(age_dt.getUTCFullYear() + today);

$j('#dateOfStar').val(age);
});

$j('#end_of_training').change();

});

Re: Date calculation

Posted: 2019-07-28 15:58
by pbottcher
Hi,

sorry I still do not get what you try to do.
What is age, age_dt, dateOfStart? dateOfStar is a selectable date in your app?

Maybe you can explain more in detail what you try and also post a screenshot.

Re: Date calculation

Posted: 2019-07-28 16:33
by Moh Youba
ok sorry for my bad English, I will try to explain

Table name : training
3 fields (start_date - end_date - duration)
start_date (date type)
end_date (date type)
duration (integer type)

I want to display date base on this calculation
start_date + duration = end_date

for exemple
start_date : 1/1/2019
duration : 5 days
end_date will display : 6/1/2019

I hope this is more clear

Thank you

Re: Date calculation

Posted: 2019-07-28 21:01
by pbottcher
Hi, assuming that duration as integer means days you want to add you could try

$j(function(){
$j('#start_date-dd, #start_date-mm, #start_date').change(function(){
var start_date = $j('#start_date-mm').val()+"."+$j('#start_date-dd').val()+"."+$j('#start_date').val();
var duration = $j('#duration').val();
var dt = new Date(start_date);
var end_date= new Date(dt.getTime() +(duration *86400000));
$j('#end_date-mm').val((new Date(end_date)).getMonth()+1);
$j('#end_date-dd').val((new Date(end_date)).getDate());
$j('#end_date').val((new Date(end_date)).getFullYear())
});
})

Assuming that start_date and end_date are datepicker fields.

Re: Date calculation

Posted: 2019-07-28 21:51
by Moh Youba
Hi
Thank you for your support, yes that start_date and end_date are datepicker fields.
I am going to try and back to you
Regards,