function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Muruganand_SforceMuruganand_Sforce 

How to Populate the datetime value using inputtext in VF

Hi,

 

I want to get(populate) a datetime input value from visual force page to custom controller. I can't use inputfield since it is not filed in  any object.

 

suggest me...

 

 

bob_buzzardbob_buzzard

You can convert a String to a date/time using the static parse method.  As that requires quite a fixed format, you might want to consider providing picklists for the various components or integrating with 3rd party calendar picker.

Muruganand_SforceMuruganand_Sforce

Hi Bob,

 

 

I want to select from calender picker...Is it possible via java script?

bob_buzzardbob_buzzard

Is this the standard date picker?  You may be able to leverage this without an inputfield, but its a fragile solution as Salesforce may change the implementation at any time.

 

Something else you may wish to consider is to use a dummy sobject with a datetime field to capture the information, then extract it out of that before continuing your processing.

Muruganand_SforceMuruganand_Sforce

Yes...It is standard date picker

bob_buzzardbob_buzzard

The easiest way is to instantiate an sobject with a DateTime field on it, and then use an inputfield.  You don't have to save the sobject to the database, you simply use it as a carrier for the field.

Muruganand_SforceMuruganand_Sforce

 

I tried to do so....but got error....Can you give few lines of it...

 

bob_buzzardbob_buzzard

In the controller:

 

public class MyController
{
   public MyObject__c carrier {get; set;}

   public MyController()
   {
      carrier=new MyObject__c();
   }
}

 in the page:

 

<apex:page controller="MyController">
    <apex:form>
       <apex:inputField value="{!carrier.Date_Time__c}"/>
    </apex:form>
</apex:page>

 

This assumes you have an sobject tpe MyObject__c with a Datetime field called Date_Time__c

 

Muruganand_SforceMuruganand_Sforce

 

I dont have sobject tpe MyObject__c with a Datetime field called Date_Time__c.

 

I should use only Inputtext not Inputfield.

 

bob_buzzardbob_buzzard

I didn't expect you to have one.  

 

Presumably you have some sobjects in your org and one of these has a date/time field?  Just replace the sobject and field names with the actual details from your org.  That way you can use an inputfield and avoid replicating the datepicker functionality.

Muruganand_SforceMuruganand_Sforce

Hi Bob,

 

I have finished the Task by writing JavaScript....Thanks for your Help.

bob_buzzardbob_buzzard

No problem.  Did you hook in to the existing datepicker or integrate with a 3rd party version?

erueru

please create Datetime field  to use Datetime  input in visualforce.

Muruganand_SforceMuruganand_Sforce

I Integrated with 3rd party version.

 

 

 

HariPHariP
Hi Muruganand,

I am looking for something similar. I need to capture date value from visualforce page. Can you please post what solution you did with sample code.

Thanks