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
du-scodouglasdu-scodouglas 

Date from a string

Is there ANY simple way to do this in apex? Why does the platform not have an inputDate field that would behave like the inputText field?

 

I have been searching around since 11:30 for this SIMPLE solution.

Cory CowgillCory Cowgill

I feel your pain. For some reason, VF doesn't support this with a inputDate tag.

 

If your able to user <apex:inputField> this will create the date picker for you. However, that requires a SObject for the field to work.

 

As a workaround, I'll create a dummy Task object on my controller, and bind to the ActivityDate on the Task. This will allow me to bind in the VF Page to the dummy Task SObject, rendering the Date Field. Then in my controller I just pass the Date field to whatever Date variable I need to.

 

It works, just wastes memory becuase your using inputField on a object that your not really doing anything with. But it at least gives you the DatePicker and only requires 2-3 lines of code, so its simplest way to do it that I know of.

 

I'll be interested if anyone has another approach.