Find your content:

Search form

You are here

How to split StartDateTime field of Activity event

 
Share

enter image description hereenter image description hereHow to split StartDateTime field of Activity event object in Visual force page i tried to retrieve it with inputfield but i can find single box but not as the standard style of the field.


Attribution to: rakesh

Possible Suggestion/Solution #1

To split a Datetime field into its constituents, you can use Datetime instance methods

You can also get the Hour, Minute and Seconds part of the time as separate strings.

Datetime nowTime = Datetime.now();
String DateStr = String.valueOf(nowTime.date());
String timeStr = String.valueOf(nowTime.time());

System.debug(DateStr + ' : ' + timeStr);

To render a Datetime field in Visualforce, you need to bake your own field to display the date and time components separately, there isn't a native field type that you can use to display like it is on the Task Edit Screen. (i.e. a Time Picker like there is a Date Picker)

You can render this as field, one an inputField of type Date, which allows you to pick the date in a calendar.

For the time, render a selectList, with selectOptions to represent the time (08:00, 08:30,....)

Here is an example of how you could render a selectList for the time part.

 public SelectOption[] getReminderTimeList() 
        {   
            TaskReminderTime = '09:00';
            SelectOption[] options = new SelectOption[]{};
            String mins = '30';
            for (Integer i = 0; i < 48; i++) 
            {
                mins        = (mins == '30') ? '00' : '30';
                Integer hrs = ((i*30) / 60);
                String hr   = (string.valueOf(hrs).length() == 1) ? '0' + string.valueOf(hrs) : string.valueOf(hrs);            

                String key = hr + ':' + mins;

                options.add(new SelectOption(key, key));
            }
            return options;   
        }

Attribution to: techtrekker
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5430

My Block Status

My Block Content