Skip to content

Instantly share code, notes, and snippets.

@W3BGUY
Last active April 21, 2021 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save W3BGUY/3dfc0141be3f1cd89c7175738f9de6ad to your computer and use it in GitHub Desktop.
Save W3BGUY/3dfc0141be3f1cd89c7175738f9de6ad to your computer and use it in GitHub Desktop.
NetSuite - Convert Date Object into NetSuite usable Date Format
// function to add leading zeros on date parts.
function zeroPad(num,len){
var str=num.toString();
while(str.length<len){str='0'+str;}
return str;
}
// function to format date object into NetSuite's mm/dd/yyyy format.
function formatNSDate(dateObj){
if(dateObj){
var nsFormatDate=zeroPad(dateObj.getMonth()+1,2)+'/'+zeroPad(dateObj.getDate(),2)+'/'+dateObj.getFullYear();
return nsFormatDate;
}
return null;
}
// example usage
var thisDate=formatNSDate(new Date());
@gainskills
Copy link

function zeroPad(num,len){
should be
function addZeros(num,len){

right?

@W3BGUY
Copy link
Author

W3BGUY commented Apr 21, 2021

Ahh, I see what you are referring to. addZeros was an intermediary function, that I removed. Good catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment