3

I have an input field in my visualforce page which uses the html 5 input element as type="datetime-local". The value that I capture from the field is of the format 2016-04-09T23:58 . I want to use and save this field on to the database in salesforce and I cant assign the same value to the field directly. Even to parse salesforce expects a different format something like this 09/04/2016 5:10 PM.

If I can do something like Datetime dt = DateTime.parse('24/11/2011 1:46 PM') then I can assign it to a field in Salesforce but there is nothing where I can use 2016-04-09T23:58 directly. I will have to convert 2016-04-09T23:58 to 09/04/2016 5:10 PM and do it.

Is there any better way to achieve this or am I missing something here

  • Allowed format for DateTime form is YYYY-MM-DDTHH:MM:SS so in user input simply add :00 as second value; – itzmukeshy7 Apr 8 '16 at 7:27
  • @itzmukeshy7 : Thanks thats a good idea and works great. – Bob Gali Apr 12 '16 at 4:02
1

Allowed format for DateTime form is YYYY-MM-DDTHH:MM:SS so in user input simply add :00 as second value;

0

Another option would be to use the DateTime.newInstanceGmt(year, month, date, hour, minute, second) method, as seen here.

Or if your datetime string is in local time, you could also use the Datetime.newInstance(year, month, day, hour, minute, second) method.

  • @itzmukeshy7 : Thanks thats a good idea and works greate – Bob Gali Apr 12 '16 at 4:01
  • @BobGali If that is the best answer, please select it by clicking the ✓ symbol. – martin Apr 12 '16 at 5:48

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.