Add/Subtract Days to a Date and pass to a Record Object

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Add/Subtract Days to a Date and pass to a Record Object

This article has been updated.(again 14th April 2009)
 
Dates can be a bit of a challenge. This article explains three points:
  • how to convert a record’s date field value into a JavaScript Date object.
  • how to add/subtract days to a JavaScript Date object. 
  • how to pass a JavaScript Date object to a record’s date field value.

1. How to convert a record’s date field value into a JavaScript Date object
var cardate = new Date (carRecord.vcar_DateMade);

Please read the article " Validation of Dates" which discusses the parsing rules that need to be followed to succesfully create a date object.

2. How to add/subtract days to a JavaScript Date object
cardate.setDate(cardate.getDate() -14 );

3. How to pass a JavaScript Date object to a record’s date field value
// myRecord is a communication record (already created)
myRecord.Comm_ToDateTime = cardate.getVarDate() ;

That’s it!! Its easy once you know!

你可能感兴趣的:(object)