Current DateTime Value to Javascript Salesforce Custom Button

To Get the Current DateTime value to Javascript Salesforce Custom Button

Current DateTime value to assign the Date Time Custom Field called “Created_Date_Time__c”.

{!REQUIRESCRIPT(“/soap/ajax/30.0/connection.js”)}
var createCase = new sforce.SObject(“Case”);
var todayDate = new Date();
createCase.Status = “Open”;
createCase.Created_Date_Time__c = todayDate.toJSON(); //DateTime Value
var caseInsrtResult = sforce.connection.create([createCase]);
window.location.reload();

Current Date value to assign the Date Time Custom Field called “Created_Date__c”.

{!REQUIRESCRIPT(“/soap/ajax/30.0/connection.js”)}
var createCase = new sforce.SObject(“Case”);
var todayDate = new Date();
createCase.Status = “Open”;
createCase.Created_Date__c = new Date().toISOString(); //Date Value
var caseInsrtResult = sforce.connection.create([createCase]);
window.location.reload();

Date and DateTime methods in Salesforce Apex Class
Example Apex Class to get the Date and DateTime values:

System.debug(‘Current Year::’ + Date.Today().Year());
System.debug(‘Current Month::’ + Date.Today().Month());
System.debug(‘Current Day::’ + Date.Today().Day());
System.debug(‘Yesterday Date::’ + Date.Today().addDays(-1));
System.debug(‘Tomorrow Date::’ + Date.Today().addDays(1));
System.debug(‘Today Date and Time::’ + DateTime.Now());

Output:

(82)

Written by 

I am Sakthivel Madesh, a certified Salesforce Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 13x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply