Add Months to Date

  • Posts: 8405
  • Karma: 164
  • Thank you received: 669

TheMuffinMan replied the topic: Add Months to Date

I am sure the reason is because a js error has been thrown.
The reason is likely this part
m = pd.getMonth();

"pd" is the plain string from that field, not a date object. We first have to convert it like this:
pd = new Date( ff_getElementByName('purchdate').value );

Then you want to add additional warranty length in months. We might need to convert the string value to an integer, just to make sure it ends up in a valid calculation (note that getMonth()/setMonth() starts with 0 in js).
wl = parseInt( ff_getElementByName('warrantylength').value );

Last but not least, we want to store the date back, but as string into your 'warrantyexpiration' element and not the date object:
ff_getElementByName('warrantyexpiration').value = pd.toString();

Given that your date format isn't compatible with "new Date()", you might need to split your date value and transform it so it will give proper result.

Have a look at the "new Date()" examples here if the above isn't working and showing odd dates:

developer.mozilla.org/en-US/docs/Web/Jav.../Global_Objects/Date

Regards,
Markus

===========================
If you are happy, please leave us a small review here to keep us motivated:
(Please turn off your VPN and local Apache prior reviewing as your review might get blocked)

⭐⭐⭐⭐⭐ BreezingForms: extensions.joomla.org/extension/contacts...orms/breezing-forms/
⭐⭐⭐⭐⭐ ContentBuilder: extensions.joomla.org/extension/authorin...tion/contentbuilder/

===========================
Satisfied?
Get a membership!
===========================
#241085
  • emtbrian2000
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 18
  • Thank you received: 0

emtbrian2000 replied the topic: Add Months to Date

Thanks for getting me on the right track! I was able to use that to find a solution. This was the code I ended up using to get it formatted correctly:
function ff_warrantyexpiration_validation(element, message)
{
	var pd = new Date(ff_getElementByName('purchdate').value);
	wl = parseInt( ff_getElementByName('warrantylength').value );
	m = pd.getMonth();
	pd.setMonth(m + wl + 1);
	var y = pd.getFullYear();
        var m = pd.getMonth();
        var d = pd.getDate();
        expdate = new String(m + "-" + d + "-" + y);

	element.value = expdate.toString();
    
    return '';
}
#241101
  • Posts: 8405
  • Karma: 164
  • Thank you received: 669

TheMuffinMan replied the topic: Add Months to Date

Hi,

so you're happy or do you need further help?

Regards,
Markus

===========================
If you are happy, please leave us a small review here to keep us motivated:
(Please turn off your VPN and local Apache prior reviewing as your review might get blocked)

⭐⭐⭐⭐⭐ BreezingForms: extensions.joomla.org/extension/contacts...orms/breezing-forms/
⭐⭐⭐⭐⭐ ContentBuilder: extensions.joomla.org/extension/authorin...tion/contentbuilder/

===========================
Satisfied?
Get a membership!
===========================
#241121
  • emtbrian2000
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 18
  • Thank you received: 0

emtbrian2000 replied the topic: Add Months to Date

I'm happy. Thanks for the help!
#241126
  • Posts: 8405
  • Karma: 164
  • Thank you received: 669

TheMuffinMan replied the topic: Add Months to Date

Great, please make sure to support the project by leaving a small review here:

extensions.joomla.org/extension/contacts...orms/breezing-forms/

Much appreciated!

Regards,
Markus

===========================
If you are happy, please leave us a small review here to keep us motivated:
(Please turn off your VPN and local Apache prior reviewing as your review might get blocked)

⭐⭐⭐⭐⭐ BreezingForms: extensions.joomla.org/extension/contacts...orms/breezing-forms/
⭐⭐⭐⭐⭐ ContentBuilder: extensions.joomla.org/extension/authorin...tion/contentbuilder/

===========================
Satisfied?
Get a membership!
===========================
#241130
Moderators: ForumSupport
Time to create page: 0.048 seconds

We Are Doing Our Part

Massive discounts on all of our extension subscription plans to help you and your business in these times.

Get Your Subscription Here

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

We are doing our part and support your business with extremely low prices -- For example 6-Months-Subscription for only $9 USD. For as long as necessary.

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!