Title: Using WordPress&#8217;s date/time format settings
Last modified: October 19, 2017

---

# Using WordPress’s date/time format settings

 *  Resolved [Morgan Kay](https://wordpress.org/support/users/gwendydd/)
 * (@gwendydd)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/using-wordpresss-date-time-format-settings/)
 * I have a plugin that relies on CMB2.
 * That plugin does a lot of stuff with dates, and I have found that users are really
   picky about date/time formats. My plugin grabs the date/time formats from WordPress’s
   general settings, and uses those formats everywhere.
 * However, I cannot get those settings to work within a metabox with a text_datetime_timestamp
   field. If I add a ‘date_format’ parameter to that field, the field data will 
   not save. Additionally, if the date format is set to ‘MM j, yy’, the format is
   displayed as ‘MayMay 05, 1717’ instead of ‘May 05, 2017’.
 * In other words, if I use this code:
 *     ```
       $shift_meta->add_field( array(
           'name' => __( 'Scheduled Start Date/Time', 'employee-scheduler' ),
           'id'   => $prefix . 'shift_start',
           'type' => 'text_datetime_timestamp',
           'date_format' => 'MM j, yy'
        ) );
       ```
   
 * the date will not save, and the format is displayed incorrectly.
 * Other people have reported these issues:
    [https://github.com/CMB2/CMB2/issues/765](https://github.com/CMB2/CMB2/issues/765)
   [https://github.com/CMB2/CMB2/issues/646](https://github.com/CMB2/CMB2/issues/646)

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [8 years, 7 months ago](https://wordpress.org/support/topic/using-wordpresss-date-time-format-settings/#post-9602723)
 * Are you basing your format from JavaScript or from PHP?
 * [https://cloudup.com/cul8XUl6Ygl](https://cloudup.com/cul8XUl6Ygl)
 * I got it to match the format you’re looking for with `'date_format' => 'M j, 
   Y'` as the documentation for the field type states it takes PHP’s formatting.
 * [http://php.net/manual/en/function.date.php#refsect1-function.date-parameters](http://php.net/manual/en/function.date.php#refsect1-function.date-parameters)
 *  Thread Starter [Morgan Kay](https://wordpress.org/support/users/gwendydd/)
 * (@gwendydd)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/using-wordpresss-date-time-format-settings/#post-9602993)
 * Thanks for getting back to me!
 * I must have been using JS time formats (it was several months ago when I was 
   working on this).
 * Things get really funky if I use European date formats. I currently have this
   as my metabox field:
 *     ```
       $shift_meta->add_field( array(
           'name' => __( 'Scheduled Start Date/Time', 'employee-scheduler' ),
           'id'   => $prefix . 'shift_start',
           'type' => 'text_datetime_timestamp',
           'date_format' => get_option( 'date_format' ),
           'time_format' => get_option( 'time_format' )
       ) );
       ```
   
 * Under Settings–>General, I have `d/m/Y` and `H:i`. `d/m/Y` is one of WordPress’s
   default date options, and is a fairly common date format in Europe. When I save
   the post, the date is blank. I’m pretty sure I know why – my guess is that CMB2
   validates the field by running `strtotime`, and doesn’t save the field if it 
   doesn’t get a valid timestamp. However, PHP doesn’t recognize `d/m/Y` as a valid
   time format – if the date separator is a `/`, PHP assumes it is American month/
   day/year, and if the date separator is a `-`, PHP assumes it is a European day/
   month/year. So even though WordPress presents that as a valid date format, PHP
   gets confused and rejects it.
 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/using-wordpresss-date-time-format-settings/#post-9603002)
 * Yah, unfortunately JS formats will not work. CMB2 does the work of transforming
   _most_ of the php formats to the JS equivalents, but I have no doubt it doesn’t
   handle all variants, as there are so many. As for your issue, it sounds like 
   the best bet would be to do some translation of the `get_option( 'date_format')`
   values before you set them as the parameter for the CMB2 field.
 *  Thread Starter [Morgan Kay](https://wordpress.org/support/users/gwendydd/)
 * (@gwendydd)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/using-wordpresss-date-time-format-settings/#post-9634702)
 * Thanks, Justin!
 * I have put in a filter to check for European date formats and put them in a format
   that PHP recognizes, but I’m running into a new issue.
 * Putting in the date format `F j, Y` results in this: [https://s.nimbus.everhelper.me/share/1209522/r9lfpqlbfo6c30u68q18](https://s.nimbus.everhelper.me/share/1209522/r9lfpqlbfo6c30u68q18)
   Where it should say October 4, 2017, it says F 4 2017.
 * That happens whether I get that format from the settings, or put it in directly
   as `'date_format' => 'F j, Y',`
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [8 years, 7 months ago](https://wordpress.org/support/topic/using-wordpresss-date-time-format-settings/#post-9635730)
 * Not completely sure why, though I suspect it’s a case of the timestamp conversion
   results in an empty string, changing the format to use the F is not saving any
   meta data.
 *  Thread Starter [Morgan Kay](https://wordpress.org/support/users/gwendydd/)
 * (@gwendydd)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/using-wordpresss-date-time-format-settings/#post-9638000)
 * Correct – changing the format to ‘F’ means that the field gets filled with ‘F
   4 2017’ instead of ‘October 4 2017’, and then the data doesn’t save because it
   isn’t a valid time format.
 * This seems to me like a bug in CMB2 because ‘F’ is a valid time format. Any idea
   why this is happening?
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [8 years, 7 months ago](https://wordpress.org/support/topic/using-wordpresss-date-time-format-settings/#post-9638247)
 * Part of an issue in general, not necessarily specific to CMB2, is that PHP and
   JavaScript follow different formatting standards, and the date/time based fields
   utilize jQuery UI. Nothing changed on my end since last night, but I haven’t 
   tried to dive back into it again yet either.
 *  Thread Starter [Morgan Kay](https://wordpress.org/support/users/gwendydd/)
 * (@gwendydd)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/using-wordpresss-date-time-format-settings/#post-9638372)
 * Right. I suspect that somewhere CMB2 isn’t correctly translating between PHP 
   and jQuery UI time formats.
 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/using-wordpresss-date-time-format-settings/#post-9638451)
 * Ok, I have updated CMB2 to translate PHP date formats to JS ones in more contexts.
   In my testing, your format (`F j, Y`) will work in the next release. [https://github.com/CMB2/CMB2/commit/7212e878dd74e393ab70fd5b0ebff302c02d1a41](https://github.com/CMB2/CMB2/commit/7212e878dd74e393ab70fd5b0ebff302c02d1a41)
 *  Thread Starter [Morgan Kay](https://wordpress.org/support/users/gwendydd/)
 * (@gwendydd)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/using-wordpresss-date-time-format-settings/#post-9638792)
 * You’re awesome! Thank you!

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Using WordPress’s date/time format settings’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

 * 10 replies
 * 3 participants
 * Last reply from: [Morgan Kay](https://wordpress.org/support/users/gwendydd/)
 * Last activity: [8 years, 7 months ago](https://wordpress.org/support/topic/using-wordpresss-date-time-format-settings/#post-9638792)
 * Status: resolved