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
Rutger GernandtRutger Gernandt 

Combining date field & time field into date/time field with daylight saving time formula length problem...

Dear all,

I am mimicing the behavior of the Event object when entering time and dates in a Custom object (because I cannot use the Event object for this use-case). To be able to show these events well in the Salesforce agenda, show them in a proper format in some tables, but also to integrate with external services I have combined the seperate date and time fields (start time + date & end time + date) in a formula date/time field.

While I have a formula for the start date & time that works well, however my formula for the end date & time is just 162 characters too long when compiling... The workaround via processbuilder is not an option, since time field are (not yet) available... 

Does anybody has a suggestion to shorter the check for the daylight saving time? As a guide to the formula's variables: Datum = Start Date, Einddatum = End Date, Tijd = Time, Eindtijd = End Time.

The functionality is: 
- if no end date & no start time is available, use start date as end date and time in such a way that it is displayed as a day length activitity in SF. 
- if no end date is available, but there is an end time: use the start date and the end time. 
- if an end date is available, but there is no end time (day length activity), use enddate and add time
- if an end date and end time is available, use these

The formula: 
IF(ISNULL(Einddatum__c),

  IF(ISNULL(Tijd__c),
 
  IF(Datum__c > (DATE(YEAR(Datum__c),3,31) - MOD(DATE(YEAR(Datum__c),3,31) - DATE(1900,1,7),7)) 
  && Datum__c < DATE(YEAR(Datum__c),10,31) - MOD(DATE(YEAR(Datum__c),10,31) - DATE(1900,1,7),7), 
  DATETIMEVALUE(Datum__c) + ((24-2)/24),  
  DATETIMEVALUE(Datum__c) + ((24-1)/24)),

  IF(Datum__c > (DATE(YEAR(Datum__c),3,31) - MOD(DATE(YEAR(Datum__c),3,31) - DATE(1900,1,7),7)) 
  && Datum__c < DATE(YEAR(Datum__c),10,31) - MOD(DATE(YEAR(Datum__c),10,31) - DATE(1900,1,7),7), 
  DATETIMEVALUE(Datum__c) + ((HOUR(Tijd__c)+1.5-2)/24) + (MINUTE(Tijd__c)/1440), 
  DATETIMEVALUE(Datum__c) + ((HOUR(Tijd__c)+1.5-1)/24) + (MINUTE(Tijd__c)/1440))),

  IF(ISNULL(Eindtijd__c),

  IF(Einddatum__c > (DATE(YEAR(Einddatum__c),3,31) - MOD(DATE(YEAR(Einddatum__c),3,31) - DATE(1900,1,7),7)) 
  && Einddatum__c < DATE(YEAR(Einddatum__c),10,31) - MOD(DATE(YEAR(Einddatum__c),10,31) - DATE(1900,1,7),7), 
  DATETIMEVALUE(Einddatum__c) - (2/24),  
  DATETIMEVALUE(Einddatum__c) - (1/24)),

  IF(Einddatum__c > (DATE(YEAR(Einddatum__c),3,31) - MOD(DATE(YEAR(Einddatum__c),3,31) - DATE(1900,1,7),7)) 
  && Einddatum__c < DATE(YEAR(Einddatum__c),10,31) - MOD(DATE(YEAR(Einddatum__c),10,31) - DATE(1900,1,7),7), 
  DATETIMEVALUE(Einddatum__c) + ((HOUR(Eindtijd__c)-2)/24) + (MINUTE(Eindtijd__c)/1440), 
  DATETIMEVALUE(Einddatum__c) + ((HOUR(Eindtijd__c)-1)/24) + (MINUTE(Eindtijd__c)/1440)))

)

Any help is higly appreciated! 

 
Best Answer chosen by Rutger Gernandt
Alain CabonAlain Cabon
Hi,

Does anybody has a suggestion to shorter the check for the daylight saving time?

That is the main problem indeed because you have duplicated this calculation several times and the solution could be to remove all the checks for the daylight saving time in this formula and to create a second formula that will only check  the daylight saving time.

You have surely thought about this workaround that is not the ideal "unique" formula solution as you hope but here there is not easy solution above all for a nice based formula like this one.
 

All Answers

Alain CabonAlain Cabon
Hi,

Does anybody has a suggestion to shorter the check for the daylight saving time?

That is the main problem indeed because you have duplicated this calculation several times and the solution could be to remove all the checks for the daylight saving time in this formula and to create a second formula that will only check  the daylight saving time.

You have surely thought about this workaround that is not the ideal "unique" formula solution as you hope but here there is not easy solution above all for a nice based formula like this one.
 
This was selected as the best answer
Rutger GernandtRutger Gernandt
Dear Alain, thanks for your reply! Will try to do so, not an optimal solution and a lot of headroom, but better than nothing. 

p.s. please excuse me for the many typo's etc. in the first post, was in a hurry. But I can't find an edit my post button actually?
Alain CabonAlain Cabon
Dear Rutger, typos? I am French and I am using a "broken English" myself (I try to improve). It is not only typos but turns of phrase and missing words that I have to be careful myself. If we understand each other, that is the most important thing.

If you arrive at a solution to this complicated problem, let us know. Your first formula was great and it is embarrassing when you have to split it (perhaps a working workaround) for just  ... 162 characters too long.

Best regards
Alain