Forums

Mootools Datepicker Date

renas 30 Sep, 2012
Hi all,

I am creating a form that need the months difference between today and a date picked from the Mootools Datepicker calendar.

How can i do this?

Many thanks to all.

Renas
GreyHead 01 Oct, 2012
Hi renas,

Do you need this calculated in the browser using JavaScript so that it can be displayed in the form; or is it enough to do it with PHP after the form is submitted?

How exactly do you define the calculation you need? What happens about part months?

Bob
renas 01 Oct, 2012
Hi GreyHead,

After some long read i have found a solution.
I am working the values onchange on the form. So, Javascript and Mootools Datepicker. I am using Joomla 2.5

For the solution i have made this:

1. On advanced edit of form, DateTime Picker config. This will guarantee that value is recalculated if date changes.
onSelect: myfunction

2. In the "Load JS" action

- For the local code of calendar. This will give me Months and Week days in my language. If supported in the Mootools DatePicker. In my case is supported.
<?php
$lang =& JFactory::getLanguage();
$tag = $lang->getTag();
echo "Locale.use('{$tag}');";
?>


- For the months difference

function myfunction(){
  start = $('calendar_box_id').value.split(' ')[0]; //Date Selected
  start = new Date().parse(start); //Parse Date
  today = new Date(); //Get Today Date
  months = start.diff(today, 'month'); //Months difference from today to selected date
};


The purpose of this code is to calculate loans.

Hope will help someone else,🙂

Tks,

Renas
GreyHead 01 Oct, 2012
Hi Renas,

Well done, thank you for posting the answer.

Bob
renas 03 Oct, 2012
Hi all,

Can anyone give me a help defining the parser of mootools date.
Hi have this date format:
format: '%d-%m-%Y'

Tks,

Renas
renas 04 Oct, 2012
Hi all,

Have tried this to extract the date.

	start = $('data_aquisicao').value.split('-')[0];
	start = $('data_aquisicao').get('date');


Both fail, anyone with the same problem?

Tks,

Renas
GreyHead 04 Oct, 2012
Hi Renas,

Please look at the earlier example and work out what each line is doing.

Also notice that you seem to have invented some JavaScript which does not match the earlier example.

Bob
renas 04 Oct, 2012
Hi GreyHead,

The problem is that i need to add months and years to the previous date.
I am using the 'increment' wich seems to get me always bad results.
loan_date.increment('month',$('integer_value').value);


For this piece of code i need to add months to initial date from the datepicker twice. To determine the end loan date and actual date.

Tks,

Renas
GreyHead 08 Oct, 2012
Hi Renas,

I think that increment() will only work if loan_date is a JavaScript date object. Is it? Looking at your earlier code it seems unlikely.

Bob
renas 08 Oct, 2012
Hi GreyHead,

I detected the problem. The increment works properly. But 'diff' don't.

It seems that Mootools diff accounts 30 days for each month. So, in 50 years this is a big difference when looking at months.

I have replaced by a custom function witch does the work perfectly.

Tks,

Renas
GreyHead 08 Oct, 2012
Hi Renas,

Thank you, that's good to know. It is documented in a little comment in the MooTools More file "// non-leap year, 30-day month" but I would never have found it.

Bob
This topic is locked and no more replies can be posted.