1

I am trying to create a VF page which has options to capture the startdatetime and enddatetime. These fields are datetime fields.

 <apex:inputField value="{!eve.StartDateTime }" id="eveStartDateTime"/>

would give one text box to enter the date and time. The user would have to change the text on the input field to change the time. What i want to achieve is to have something like the start and end on the events object.

One way i could think of was to have 1 inputText and one selectoption, one to capture the date and select option to capture the time and then join them together and save them as a datetime.

Is there a better way of doing this? Going by what i had thought of still gives me an error.

 <apex:pageBlockSectionItem> may have no more than 2 child components

The idea is to have a label and date and time together.

<apex:pageblockSectionItem>
         <apex:OutPutLabel Value="Start"/>
          <apex:inputtext value="{!StartDate }" id="eveStartDate"/>
         <apex:selectList id="eveStartTime" value="{!StartTime}" size="1">
                <apex:selectOption itemValue="00:00" itemLabel="00:00"/>
                <apex:selectOption itemValue="00:30" itemLabel="00:30"/>
                <apex:selectOption itemValue="01:00" itemLabel="01:00"/>
                <apex:selectOption itemValue="01:30" itemLabel="01:30"/>
                <apex:selectOption itemValue="02:00" itemLabel="02:00"/>
         </apex:selectList>
         </apex:pageblockSectionItem>

Is there any other way to achieve this?

if i join the date and time in a string and then convert that string to Datetime and save it would it save the time in the users timezone?

1
  Date   d=System.Today();
    String sDate = String.valueOf(d);
    string datime='13:00:00';
    string stringDate=sDate+' '+datime;
    System.debug('The concated String :'+stringDate);
    Datetime myDate = datetime.valueOf(stringDate);
    System.debug('The value of myDate'+myDate);

enter image description here

I did some serious analysis on this and as you can see the code above i drafted will surely work for you.

Consider few points

1)Dont hard code in select option .Use Custom setting for Same .This will give flexibilty for admin to add or modify later

2)Even in Debug log you may see different time but yes no issues on that since it always shows in GMT and according to the local of the user value will be adjusted .

3)You can use standard date field for the user to allow select the Date.

  • Thanks mohith.. How can we have the label, field for date and field for time in one blocksectionitem? Any thoughts on that.. – Prady Nov 23 '12 at 6:46
  • Use Pageblock Section Item and since it takes only two componets use OutputPanel to bind label for date and input field and use another OutputPanle to bind label for time and input and have in Pageblocksectionitem. – Mohith Shrivastava Nov 23 '12 at 6:49

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.