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
Tina HadariTina Hadari 

Passing a datetime parameter to a query in the controller formatting issue.

So  I have a visual force page with a page block table that when a user makes a selection it passes the date time from the page to the controller that uses it in a query. However the parameter is passing the date time in the following format:

Fri Nov 30 21:55:38 GMT 2012

and I can't seem to figure out how to put it back into the format the database seems to use:

"2014-01-24T16:56:27.044Z"

Is there an easy way to perform this conversion or to adjust my query to accept the parsed out date time value? 


 
Anupam RastogiAnupam Rastogi
Hi Tina,

As I understand, you are passing current Date Time to the controller when the user is making a selection on your VF page. This date time is then used in a query which is expecting a different format.

I suggest you to change your approach a little bit here to check the results. Here is what you can try to do - 

   - Make use of DateTime.Now() to get the current date time when the user makes the selection on the VF Page. So basically, rather than passing the date time from the page to the controller, you can get it within the controller itself.

When I do a system.debug of the date time retrieved using NOW() from within the controller I get the value in the required format.

Thanks
AR

If you find the reply useful that solves your problem then please mark it as best.