This topic contains 9 replies, has 0 voices, and was last updated by CREECE 7 years, 7 months ago.
- 
		AuthorPosts
- 
February 23, 2017 at 9:58 am #1140
 ssilveri77There doesn’t appear to an addmonth in native javascript. Has anyone found an equivalent in 2.0 ? 
 This is a cached copy. Click here to see the original post.
- 
February 23, 2017 at 10:15 am #1141
 karennYeah I was having the same issue. Using the following var today = new Date(); var sixmonthsago = new Date(); sixmonthsago.setMonth(sixmonthsago.getMonth() – 6); 
- 
February 23, 2017 at 10:25 am #1142
 ssilveri77Originally posted by karenn View Post Yeah I was having the same issue. Using the following var today = new Date(); var sixmonthsago = new Date(); sixmonthsago.setMonth(sixmonthsago.getMonth() – 6); Yes. I found set month only sets the month number. It does not increment/decrement the year. Many seemed to be using Javascript libraries with addmonth functions 
- 
February 23, 2017 at 10:44 am #1143
 cblackburnWe recommend that people have a look at MomentJS for date arithmetic. 
- 
February 23, 2017 at 10:55 am #1144
 ssilveri77Originally posted by cblackburn View Post We recommend that people have a look at MomentJS for date arithmetic. Interesting. I will try it. Thanks 
- 
February 23, 2017 at 11:46 am #1145
 ssilveri77Originally posted by cblackburn View Post We recommend that people have a look at MomentJS for date arithmetic. Do I need to update the moment.js with define and return statements or can I use it as is… 
- 
February 23, 2017 at 11:52 am #1146
 erictgrubaughmoment.js is AMD-compatible as-is. I am currently using it in some 2.0 scripts just fine. Uploaded the .min version to the File Cabinet, and included it in my 2.0 portlets with no issue or modifications needed. 
- 
February 23, 2017 at 11:55 am #1147
 david.smithI like momentsjs but I’m not a big fan of loading unnecessary code. Here are a couple functions that you might be able to use. Code: 
 function addMonths(date,months){
 var d= new Date(date.getFullYear(), date.getMonth()+months, date.getDate());
 return d;
 }function daysInMonth(date) { 
 return new Date(date.getYear(), date.getMonth()+1, 0).getDate();
 }
 ironside replied on 02/23/2017, 10:40 PM: Not to be contrarian, I disagree with david here. I’m not a fan of _writing_ unnecessary code. My recommendation is to use momentjs instead of writing buggy code ones self. 
- 
April 3, 2017 at 7:23 pm #1148
 cblackburnOriginally posted by ssilveri77 View Post Do I need to update the moment.js with define and return statements or can I use it as is… It should work as-is, MomentJS will detect the presence of an AMD module loader and register with it if present. 
- 
April 4, 2017 at 12:29 am #1149
 CREECE+1 for MomentJS. If you need to go back to date objects or strings formatted to your user prefs/company prefs (which is a lot of the time), be sure to use the N/format module and its format.format / format.parse methods. Also be sure to always use date ob 
- 
		AuthorPosts
You must be logged in to reply to this topic.
