We have to separate fields to pick appointment date & appointment time in Custom object. Now we have to filter out appointments between two dates (w/ time), so I need to compare appointment date & time both. For that, I am thinking to create a Formula field which takes both appointment date & time & provide appointment date & time in date/time type. Please provide formula to do so

  • what you have tried so far? – Santanu Boral Aug 16 '18 at 9:37

You can handle this in Apex like this:

DateTime dt = DateTime.newInstance(myDate, myTime);
| improve this answer | |
  • Awesome, just what I needed- simple and clean. Thank you! – Navigatrix Apr 9 at 15:28
  • OP asked for a formula – Scott Pelak Jul 15 at 14:49

DATETIMEVALUE(TEXT( App_Date__c )+ " "+ TEXT( App_Time__c ))+x/24

Note: X incidate time Zone difference (Kindly check user setting to know the Time Zone that has been mapped Name-> My Settings -> Language & Time Zone)

| improve this answer | |

I have tried formula field using below,

DATETIMEVALUE(TEXT(Appointment_Date__c) + " " + LEFT(TEXT(Appointment_Time__c), 8)) + 7/24

But since it will not work only for daylight saving period (GMT-7), but not for standard timezone (GMT-8). So formula field doesn't work for such timezones.

For such timezones, we have the only option of Apex, so I created trigger & it worked.

trigger UpdateAppointemntDateTime on Ride__c  (before insert,before update) {
    for(Object__c r : trigger.new)
        if(r.Appointment_Date__c != null && r.Appointment_Time__c != null){

            String timeString =  String.valueOf(r.Appointment_Time__c);

            r.Appointment_Date_with_Time__c = DateTime.newInstance(r.Appointment_Date__c, 
                                            0, 0));

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.