Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
rakesh please post screen shot and your code ? – Mohith Shrivastava Dec 14 '12 at 9:45
hi Mohith i add screen shot – rakesh Dec 14 '12 at 10:46
up vote 1 down vote accepted

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 =;
String DateStr = String.valueOf(;
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;   
share|improve this answer
very nice loop for the time selectList. although i love a good ternary :) , here is a little trick i picked up a while back for working with date / time components that is now possible in apex with the new string methods: String hr = ('0'+(string.valueOf(hrs))).right(2); will always give you a 2-digit component. a bit cleaner maybe? – zjeh Dec 14 '12 at 20:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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