3

What format do I need to enter when setting a default value when creating a datetime field?

5

You need to use DATETIMEVALUE(...) function, like this:

DATETIMEVALUE("2013-11-15 12:00:00")

Or just NOW() function

Read more about functions

1

Default format to set DateTime field is:

In Apex code and formula function:

2008-10-5 12:20:20

In visualforce page you can use format like:

<apex:outputText value=" {0,date,MM/dd/yy HH:mm a}">
       <apex:param value="{!bind_field}"/>
</apex:outputText>
0

Use NOW() if you want the current time. NOW() will return the current time in the user's time zone.

Use DATETIMEVALUE("YYYY-MM-DD HH:MM:SS") if you want to set a specific date/time. However, this function determines the time in GMT, then displays it in the user's time zone, so if you want the time in the user's time zone you may need to add or subtract the time zone offset.

For example, DATETIMEVALUE("2013-09-01 00:00:00") will return "8/31/2013 5:00 PM" for a user in Pacific Daylight Time -- if you actually wanted the date/time to be "9/1/2013 12:00 AM" in PDT you would need to set the default value to DATETIMEVALUE("2013-09-01 00:00:00") + 7/24 (PDT is GMT - 7).

Calculating time zone offsets in a formula are a challenge due to Daylight Saving Time and users in different time zones -- it's probably easier to do this in Apex.

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.