Text Size

Setting the default date to GMT in a CFWheels ColdFusion App

I've been working on an app in ColdFusion for a client that needs to use dates/times across multiple countries, and thought I'd post this in case anyone else needs it. We are using CFWheels and I needed a way to ensure that the dates the framework automatically creates for the createdat and updatedat fields are in GMT time. There are a couple of  ways to do this, the first being to set your ColdFusion JVM settings to include a default timezone using an argument like "-Duser.timezone=GMT" in the JVM arguments fields of the CF Administrator. However, this will then set it for all apps on the ColdFusion server. If you only need it for the one CFWheels app, you can override the following method in your Model.cfc class:

<!--- Override the default timestamping with the GMT time --->
<cffunction access="public" name="$timestampProperty" output="false" returntype="void">
        <cfargument name="property" required="true" type="string">
                        this[arguments.property] = DateConvert(&quot;local2utc&quot;, now());

This will ensure that all date values saved to the database will useUTC/GMT time.  


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.