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: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"/>

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 Answer 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
    Commented Nov 23, 2012 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. Commented Nov 23, 2012 at 6:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .