function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Esther Thomas 2Esther Thomas 2 

adding hours to datetime not updating

Hi All,
  I want to add hours to a custom field and save the record. I'm able to save but when I look at the value for my custom field,
End_Date_Time__c it's the exact same as my Start_Date_Time__c. I'm not sure what I'm missing here. Thanks in advance for any help. 
 
public PageReference save(){
        try{
             //calculate end date/time
             hours=2;
             Records.End_Date_Time__c = (Records.Start_Date_Time__c + (hours/24));
                
             //assign client to new booking??????
             Records.Client__c = SelectedClient;
            
             //assign Availability/sitter?????????
             Records.Availability__c = SelectedSitter;
        
            insert Records;
        }catch(Exception e){
           
        }
            
        return null;
    }

 
sfdcMonkey.comsfdcMonkey.com
hi esther, 
  try below code :
 
//calculate end date/time
             hours = 2;
			 datetime d = Records.Start_Date_Time__c;
			 datetime finalDate =  d.addHours(hours);
             Records.End_Date_Time__c = finalDate;
                
             //assign client to new booking??????
             Records.Client__c = SelectedClient;
            
             //assign Availability/sitter?????????
             Records.Availability__c = SelectedSitter;
        
            insert Records;

i hope it helps you.
      Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
    thanks 
    sfdcmonkey.com