0

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
1

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)

0

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, 
                                            Time.newInstance(
                                                Integer.valueOf(timeString.split(':')[0]),
                                                Integer.valueof(timeString.split(':')[1]), 
                                            0, 0));
        }
    }

}
0

It would be better if you handler this in Apex like this:

DateTime dt = DateTime.newInstance(myDate, myTime);

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.