Date and Time Picker field for Advanced Custom Fields

screenshot-2

This is an add-on for the Advanced Custom Fields (ACF) WordPress plugin, that allows you to add a Date and Time Picker field type. Works with ACF v3 and v4.

Changlog

  • 2.0.12 Added support for date format dd/mm/yy + bug fix
  • 2.0.11 Added option to retrive field values, using the_field() and get_field(), as a timestamp
  • 2.0.10 Removed “value” from defaults
  • 2.0.9 Thanks to flahertydaf, the plugin is now working with the latest ACF version. Also replaced DateTime::createFromFormat (PHP 5 >= 5.3.0), with strtotime and did minor bugfixes
  • 2.0.8 Adds option to store the date and time field as a UNIX timestamp or not.
  • 2.0.7 Bug fix. 2.0.6 assumed that the stored date and time was in UNIX timestamp format. 2.0.7 will check and only convert if the date and time is.
  • 2.0.6 Changed how the Date and Time Picker field is triggered when ACF adds a new Date and Time Picker field to the DOM. Saves the Date and Time Picker field as an UNIX timestamp to MySQL. Use the PHP date function when you use it in your theme.
  • 2.0.5 When enqueuing JavaScripts, replaced dependecy of jquery-ui-datepicker with acf-datepicker
  • 2.0.4 Updated JavaScript language detection and loading
  • 2.0.3 Fixed Repeater field bug. Added support for including the field in a theme
  • 2.0.2 Total rewrite, based on the acf-field-type-template. Works with ACF v3 and ACF v4.
  • 1.2.0 Updated jquery-ui-timepicker-addon.js to the latest version (1.0.0) and added localization support.
  • 1.1.1 Fixed a small bug
  • 1.1 Change name to Date and Time Picker to reflect the new option to select between Date and Time picker or Time Picker only. Thanks to Wilfrid for point this out (not sure why I didn’t include it in 1.0)
  • 1.0: Initial version

Latest version

Prerequisite

Advanced Custom Fields WordPress plugin installed and activated.

Installation

This add-on can be treated as both a WP plugin and a theme include.

Install as Plugin Copy the ‘acf-date_time_picker’ folder into your plugins folder Activate the plugin via the Plugins admin page

Include within theme This doesn’t work at the moment, I’m looking into it.Copy the ‘acf-date_time_picker’ folder into your theme folder (can use sub folders). You can place the folder anywhere inside the ‘wp-content’ directory Edit your functions.php file and add the code below (Make sure the path is correct to include the acf-date_time_picker.php file)

Create a Date and Time Picker field

Add Date and Time Picker field
To set the date and time format when you create the field, you have to create a string using the letters below. Date format

d    day of month (no leading zero)
dd   day of month (two digit)
o    day of the year (no leading zeros)
oo   day of the year (three digit)
D    day name short
DD   day name long
m    month of year (no leading zero)
mm   month of year (two digit)
M    month name short
MM   month name long
y    year (two digit)
yy   year (four digit)

Time format

H    Hour with no leading 0 (24 hour)
HH   Hour with leading 0 (24 hour)
h    Hour with no leading 0 (12 hour)
hh   Hour with leading 0 (12 hour)
m    Minute with no leading 0
mm   Minute with leading 0
s    Second with no leading 0
ss   Second with leading 0
l    Milliseconds always with leading 0
t    a or p for AM/PM
T    A or P for AM/PM
tt   am or pm for AM/PM
TT   AM or PM for AM/PM

Examples

  • yy-mm-dd: 2013-04-12
  • HH:mm: 24 hour clock, with a leading 0 for hour and minute
  • h:m tt: 12 hour clock with am/pm, no leading 0

Retrieving Time Picker values

To get a general understanding on how to retrieve values from ACF, see the examples in the ACF Documentation.

Simple example

Get the field in the same format as you set it when you created the field, using get_field():

Changing date and time format

When adding a date-and-time field, choose “Get field as timestamp” and use date_i18n to do something like this:

Together with the repeater field

Here’s how I retrieve that values from the example in the screen shot

Localization

The plugin will, based on WPLANG in wp-config.php, try to load the correct localization/jquery-ui-timepicker-LOCALE.js file.

If your language doesn’t exist in localization/jquery-ui-timepicker-LOCALE.js, you have to do the translation your self:

  1. In acf-date_time_picker/lang, copy acf-date_time_picker.po to acf-date_time_picker-languagecode_COUNTRYCODE.po e.g: acf-date_time_picker-nb_NO.po
  2. Edit the file using poedit or its like, and save the .mo file in acf-date_time_picker/lang

Debugging

If you suspect that acf-date_time_picker doesn’t enqueue the scripts in the right order, install acf-debug-list-enqueued-scripts and add the field “ACF DEBUG: List Enqueued Scripts” to your fields. When you open Posts->Add New, you should get a list like the following:

Credit

Date and Time Picker field for Advanced Custom Fields uses the jQuery timepicker addon by Trent Richardson. Copyright 2012 Trent Richardson. Dual licensed under the MIT and GPL

140 thoughts on “Date and Time Picker field for Advanced Custom Fields

    1. PerS Post author

      In hindsight, I agree. I will update it this plugin to let you choose between DateTime picker and Time picker.

      Reply
    1. azyogadude

      hi
      i am trying to extract hour & minute from date time picker but has no idea what function to use .

      Thanks

      Reply
  1. Tai

    Am having issues :) On posts the date / time picker field is just displaying as a text field. When you click on it the date / time picker is not loaded. I have tried disabling other plugins, removing other jquery scripts I was using and removing other custom acf fields. Any ideas?

    WordPress: 3.3.1
    Acf: 3.1.6

    Reply
    1. PerS Post author

      Have you tested for javascript errors (using firebug etc) ?

      I’m also running WordPress 3.3.1 and ACF 3.1.6, and I can’t find any errors.

      Reply
    2. PerS Post author

      .. also, do a view-source and see if the links to the following files exist and are correct:

      • acf_time_picker/js/jquery-ui-timepicker-addon.js
      • acf_time_picker/js/timepicker.js
      • acf_time_picker/css/jquery-ui.css
      • acf_time_picker/css/timepicker.css
      Reply
  2. Dale Jacobs

    Great plugin, thank you!

    I trying to get the saved data to be yyyy-mm-dd hh-mm in the database, but display mm/dd/yy hh:mm for the editor section.

    Editing your custom field, I thought I could use the update_value function to do the saving of the new date format with the below:

    // do stuff with value
    //$value = date(“Y-m-d g:i”, strtotime($value));

    But it doesn’t seem to be firing the update_value, and just saving the default field value that is shown.

    My plan was the than to grab the value and display it differently for the edit post screen with the below:
    value=”‘ . date(“m/d/Y g:i”, strtotime($value)) . ‘”

    Do you happen to have any idea why the Update_value is not working on save?

    Maybe this would be an option to add for the plugin if we can get it working? This was sorting with WP_Query and date/time field would sort correctly but the client would still see a pretty date format in the admin section.

    Reply
  3. Tai

    Ah yes, was a space in my theme name >.< so was incorrect path to js and css files.

    Awesome plugin extension, cheers

    Reply
  4. PerS Post author

    Hi Dale,

    This is my first add-in to ACF. I’ll dive into the code and see if I missed something (haven’t looked at Update_value, so I must be missing something). I’ll post here when/if I find a fix.

    Reply
  5. PerS Post author

    update_value in my add-in is triggered. I added the following to log what was happening:

    And got this in acf_time_picker/log/log.txt ( acf_time_picker/log is world writable):

    Reply
    1. Dale Jacobs

      I wonder what I am doing wrong.

      Here is the function I edited, I am using the basic srtoftime to take out any extra variables. The field has “mm/dd/yy hh:mm” in it. After saving, it uses that format instead of stroftime. When you ran the test did it update the date post_meta in the database with the new value?

      From the log it would mean it might be on ACFs end?

      Thank you for taking the time on this.

      Reply
      1. PerS Post author

        Just tested and it worked fine, got 1333589100 when I retrieve the value in my theme. Are you sure you are retrieving it correctly ?

        Reply
        1. Dale Jacobs

          Firstly I want to apologize for using your pressure time on an issue that was my fault. I had duplicated an advanced custom post type post, so in the post meta there were two “start_date” fields with the same field_randomstrings. I deleted the duplicate field and created a new Start Date and it works as its meant too, again I feel bad I used your time (also wasting hours of my own!)

          Maybe adding a checkbox to save unix or wordpress date stamp in database could be an option you add in any future release?

          For anyone else who wants to be hack/show a clean date for the client, but add a database entry that will be easily sortable by queries, you can use the below code.

          In the file acf_time_picker.php in the function “update_value” add the line below. This will add the date format as normal post dates.

          Then to show a different date for the client in the admin section and front end add the below line to “get_value” function.

          With the above make sure to set the php date format to what you set when you added the timepicker field.

          Reply
          1. PerS Post author

            No problem Dale, glad you got it to work.

            I’ll look into adding this option to the add-in, it’s a good idea.

  6. ikemarrus

    I’m getting these warning messages when I try to define a timepicker field:

    Notice: Use of undefined constant acf – assumed ‘acf’ in path/acf_time_picker/acf_time_picker.php on line 104

    Notice: Use of undefined constant acf – assumed ‘acf’ in /path/acf_time_picker/acf_time_picker.php on line 105

    Reply
    1. PerS Post author

      Yepp, you are correct. Thank you for notifying me. It’s fixed and a new version is available in the download link above.

      Reply
  7. Stian Andreassen

    Brilliant plugin! Thanks, Per!

    Is there any way to use localization? The jQuery timepicker comes with language files, yes?

    Reply
    1. PerS Post author

      Selvsagt :)

      The following is localized:

      Reply
  8. Stian Andreassen

    Hur bra som helst! ;-)

    Would be great if there was localization for names of days and months.

    Reply
    1. PerS Post author

      I see what you mean. I will add localization for days and months using jquery-ui-i18n.min.js, but I don’t have time until next week-end.

      Reply
    2. PerS Post author

      The latest version, supporting localization, is available (got some spare time). Please test

      Reply
  9. Jonny

    Using get_stylesheet_directory_uri() to enqueue scripts is not good practice as it makes assumptions about where the script will be located which is always a bad idea. Better to use dirname(__FILE__).

    Reply
    1. PerS Post author

      Eh .. I was a bit quick. According to the wp_enqueue_script() documentation, the $src parameter should “use plugins_url() (for Plugins) and get_template_directory_uri() (for Themes) to get a proper URL”.

      I’m open to reconsider, but then your argument, with example code, must be good ;)

      Reply
      1. Jonny

        plugins_url(script_file, __FILE__) would be the correct way to do it I think where script_file is the script filename relative to the plugin directory.

        Reply
  10. Su

    I’m seeing similar behavior to Tai above(unresolved), but in looking into things, there’s something weird going on:

    1. The stylesheets and scripts required by the field /are/ being included in the source…
    2. …but their URLs result in a 404 page from WordPress…
    3. …but only due to the query parameter.

    So for example, the jQuery UI CSS is being loaded via:
    example.com/wp-content/themes/mytheme/acf_time_picker/css/jquery-ui.css?ver=3.4
    That URL produces a 404 screen, but:
    example.com/wp-content/themes/mytheme/acf_time_picker/css/jquery-ui.css
    loads properly.

    This is happening for the resources your field is loading ONLY. I have all sorts of other plugins loading various things on this install.
    One thing possibly worth noting is that yours is the only code that’s pulling CSS/JS from the theme directory to the admin area. Maybe there’s some kind of edge case there? I don’t think I’ve seen it done before.
    I’m using WP 3.4.

    I’m going to try and repro this later on a cleaner, unrelated installation and/or add plugins back in to see if there’s a conflict, but wanted to document in case someone can do anything with just this.

    Reply
    1. PerS Post author

      Hi Su,

      Thank you for your thorough feedback.

      Before I dig into the WordPress source; Have you flushed the permalink cache after you upgraded to 3.4 ? You flush the permalink cache by re-saving your permalinks in wp-admin >> settings >> permalinks

      Reply
      1. Su

        It must’ve been something along that line. Unfortunately, it’s “fixed itself” so I can’t absolutely confirm. I’d already deleted the custom field and removed the include code from functions.php, and after re-adding them just now the picker comes up properly.

        I’m pretty sure that in the interim I did /not/ modify any content or the permalink settings(it’s a dev install and I’m only doing theme work), but I assume that cache is periodically rebuilt on its own.

        I’ve still got some things to do in there, so I’ll try and pay closer attention to see if it comes up again.

        Reply
        1. PerS Post author

          Isn’t it fun when things “fixes itself” :)

          Please don’t hesitate to contact me if it happens again (or if you find new bugs).

          Reply
  11. Brent

    Great add-on! However, I’m having trouble querying a Date/Time field and sorting by the value. Has anyone else had success with this? Thanks.

    Reply
  12. zander

    Hi,

    the files aren’t linking properly in the source – it seems to be being caused by the version number which is beign put into the head… so the link in my source is ‘a href=’http://www.mysite.org.uk/dev/wp-content/themes/mytheme/acf_time_picker/css/jquery-ui-timepicker-addon.css?ver=3.4.2′

    that url resolves without the version number. so how do I stop it enqueing with the version number?

    Reply
  13. Sascha

    Hi

    For me the date / time picker is not displayed.
    It seems as if the two JavaScript files are not included. But the two CSS files, however, are involved.
    What can I do?

    Reply
    1. PerS Post author

      Excellent, you had me worried. You’re the only one that’s reported this “bug”. What’s the name of the other plugin ?

      Reply
  14. TheWalker

    Hi,

    Very nice add-on for ACF!
    I changed the function get_value and update_value, to change the format of date, without change the format of input to user.
    The reason for do that, is get posts ordered by date and time using the meta_query.

    Input: dd/mm/yy hh:mm
    Saved Field: yy-mm-dd hh:mm

    I don’t know if this is the right way, because the user can select Date and time, or only time in custom fileds configuration.

    The code:

    Reply
  15. niek

    Hi guys,
    Am struggling to find the right info on how to adjust the way the date displays on my site, currently like this: 20121129, and should be: 29 November 2012. Any advice would be much appreciated!

    Reply
      1. niek

        Thanks, I’d hoped it was that simple, but actually I need it to display that on the actual site, not just in the admin… ?

        Reply
        1. PerS Post author

          It will have the same format as in the admin, as long as you don’t modify the data in update_value. If you do, you have to reformat it before you display it in your theme.

          Reply
  16. Carl Wilhelm

    Okay, so I tried installing this addon, and now my site has gone haywire:

    Warning: include(/PATH/wp-content/themes/arthemia/acf_time_picker/acf_time_picker.php) [function.include]: failed to open stream: No such file or directory in /PATH/wp-content/plugins/advanced-custom-fields/acf.php on line 218

    Warning: include() [function.include]: Failed opening ‘/PATH/wp-content/themes/arthemia/acf_time_picker/acf_time_picker.php’ for inclusion (include_path=’.:/usr/share/pear:/usr/share/php:/PATH/wp-content/plugins/mailchimp-widget/lib’) in /PATH/wp-content/plugins/advanced-custom-fields/acf.php on line 218

    Fatal error: Class ‘acf_time_picker’ not found in /PATH/wp-content/plugins/advanced-custom-fields/acf.php on line 220

    Any suggestions?

    Reply
    1. PerS Post author

      Looks like you have an error in arthemia/functions.php where you include the time picker field. Please post what you added.

      Reply
  17. Carl Wilhelm

    Never mind, the addon works just fine. I put the addon-files in the wrong place.

    Thanks for this! This is going to make things a lot easier. I find it weird that isn’t a standard feature in ACF to be honest.

    Reply
  18. Carl Wilhelm

    For some reason, the buttons for the next and previous months are missing from the date & time picker window. It’s worked a few times before, but I can’t figure out what’s wrong. One thing I’ve noticed is that when the buttons are missing, the background for header where the name of the month is displayed is blue. When the buttons are there the header background is gray. Could this stem from a plug-in conflict or something like that?

    Reply
      1. Szymon Skulimowski

        Thats right but this plugin is “Advanced Custom Fields” :)
        http://i.imgur.com/G1zQWV4.png

        You should simple add this line into acf_time_picker/css/jquery-ui-timepicker-addon.css:

        Reply
  19. Alicia St Rose

    Hi PerS,
    Just downloaded this addon. It looks like it’s just what I need. But I can’t seem to make it work! Added the files but I’m getting a text field and no time picker. I’m a noob don’t know what doing wrong…

    Reply
  20. Alicia St Rose

    Hi PefS,
    Turns out my client doesn’t need a time picker. I will revisit this in the future and add the debug file to see what the problem is. Thanks for your quick response!

    Reply
  21. David Mosterd

    Hi,

    Great stuff this time picker. I have made a change to it and hope you will add this to your code. (Why not place it in github so we can all do pull requests?)

    http://pastebin.com/YzUAYZ16

    I found it rather a pain that I was forced to place this into my theme folder as I like to keep external things organized. Now it takes __FILE__ and assumes it’s somehwere in the themefolder.

    Check it out. But I have even an better idea. Why not place it on github and lets make this into a plugin? That will be just…. right.

    Let me know if your up to it, if not, I will do it myself but I rather have the original author do this of course.

    Cheers!

    David

    Reply
  22. David Mosterd

    Hi,

    Checkout http://pastebin.com/YzUAYZ16

    It now uses __FILE__ so you can place it anywhere in your theme.

    If you are up to it: why not make this into a GitHub repo and turn this jewel into a plugin?
    We can use GItHub to develop and use the official WP repo to distribute this.

    Let me know if you are up to it! Or is there a secret GitHub? Could not find it ;)

    Reply
  23. eaglejohn

    It seems that the add-on “Date & Time Picker” doesn’t work in v4.0 Beta? I’ve used it before in v3.5.8.1 without problems. Any suggestions?

    Reply
    1. PerS Post author

      Thank you for telling me. I haven’t tested it myself with 4.0 (since it’s still in beta), but will have a look this week-end.

      Reply
      1. eaglejohn

        Elliot (ACF developer) replied to my post on the ACF support forum and he told me he has to fix it because things work different in 4.0 (beta).

        Reply
  24. ColouRo

    Hi,
    I installed the plugin, but have one problem.
    When I click on input I get this error:
    Uncaught TypeError: Object [object Object] has no method ‘datetimepicker’

    Maybe someone knows how to fix it?

    Reply
  25. Elliot Condon

    Hi Guys,

    I’m Elliot, the dev behind ACF and just wanted to say hi, thank you for making this field and also chat about the new ACF v4.

    Unfortunately, in v4, I have had to change the way in which we define custom field types, this means your field is not compatible with the new ACF and wont work.

    This said, it will not require much work at all to create a v4 compatible field type!
    Please read the new documentation for creating a field type here:
    http://www.advancedcustomfields.com/docs/tutorials/creating-a-new-field-type/

    You will find that some functions have changed names. I advise that you start with a blank dummy.php field file and copy across your old functions one by one into the new function spaces.

    I’m more than happy to help out with creating a v4 compatible field type, just let me know.

    I’m not sure if you would want to create a new repository or just a new branch, but either way, both versions will need a url for users to find.

    I’m sorry about causing any extra work and hassle, thanks for all your hard work, it’s greatly appreciated!

    Cheers
    Elliot

    Reply
    1. PerS Post author

      Hi Elliot, I’m on a business trip, but will look at ACF v4 this coming week-end. Thank you for offering your help, I’ll bug you only if needed :)

      Reply
  26. John Snow

    Hey, if you change “self = jQuery(this);” to “var self = jQuery(this);” on line 6 of timepicker.js it stops causing errors in Internet Explorer 8.

    Reply
  27. Tim Wood

    I really like this addon – and the slider is great; however, I’ve had a few integrations where it would be helpful if A) it was a dropdown instead of slider & B) if it showed 12 hour time instead of military time. Any chance those are available in upcoming release?

    Reply
    1. PerS Post author

      Hi Tim, thank you for your feedback.

      Ref A, I guess you want this for mobile users? It’s a good idea and I’ll try to add it as an option in the next release (coming this week). As of B, you have this option today. You set the time format when you create the field.

      Reply
  28. Enrique

    Thank you for your great contribution. I’ve found that the time is saved in Unix timestamp but when it’s read it takes into account the default timezone set in wordpress. So currently I’m on the UTC+ 2 timezone and if i save 17:00 it returns 19:00.

    The workarround in function load_value in date_time_picker-v4.php

    Reply
    1. PerS Post author

      Let’s assume the following:
      - the filed name is: mydate
      - your date and time format is: m/d/yy h:m tt

      Reply
  29. Ben

    Thanks for the great add-on.

    When I set the date format in the date field settings to “dd/mm/yy” it is saving the day as the month, and the month as the day. Can you help?

    It works fine if I use “mm/dd/yy”. I did try reading through the posts above but couldn’t see a solution.

    Reply
  30. B Bolla

    Hi,

    i’m having issues with changing the date format to 24hr. Current Date format: YYYY-MM-DD hh:mm:ss

    I realise i need to change form hh to HH. But i have no idea how to do this.

    I have installed the plugin “Advanced Custom Fields: Date and Time Picker”

    Please can someone help me as i am limited skills in this area?

    Reply
  31. B Bolla

    Hi,

    Can someone please help me.

    I have installed the plugin “Advanced Custom Fields: Date and Time Picker”

    Please can someone tell me how to change to a 24hr time?

    I am a complete novice at this and would appreciate some basic instructions!

    Reply
  32. Scott

    I’ve added a custom field to a custom post type, but it’s not saving (or showing ) the Date Time field value. I’ve tried it with and without the timestamp. And i’ve tried it with the regular post type. I’m running PHP 5.3. Any ideas why my values are not saving?

    Reply
  33. Scott

    It’s actually saving it in the custom field in the DB so i guess it’s KIND of working. But it’s not showing the value in the meta box field itself. And when i try to resave it, since it’s a required field, it’s needs a new value in the meta box.

    Reply
  34. Josh Emerson

    I am trying to get the ACF date/time picker to work on a site I am building. It seems like it would be the perfect solution but upon selecting a time and updating the entry, it does not show. If I switch the field type to a text field it shows what seems like a unix time number. Is there a way to get the time picker to display the time I input?

    Reply
  35. Benjamin A. Wendelboe

    Hey Per,

    Thanks for a great plugin – I am however having a bit of an issue with the time picker, that I was hoping you could help me with..

    When I go back to edit a post, my “time”-field is empty.. I tried changing the field type to “number”, and suddenly the UNIX timestamp shows up, but no matter what else I do to tinker with it, I have to re-enter the value on every edit..

    Any help would be appreciated..!

    Reply
  36. Larry Woods

    Blows when trying to publish a post with date/time:

    Fatal error: Call to undefined method DateTime::createFromFormat() in …/wp-content/plugins/acf-field-date-time-picker/date_time_picker-v4.php on line 293

    Reply
  37. Larry Woods

    I am using the date in a POST edit. Any way to get the date do display after I have once entered/updated the POST?

    Thanks

    Reply
  38. Roger Henriksen

    Hei,
    Ser at du svarer på skandinaviske henvendelser, så jeg prøver på norsk. Dette er kanskje litt ved siden av henvendelse ellers i denne tråden, men håper du har tid til et svar:

    Jeg har et problem med en oversettelse for en kundeside. Jeg bruker Advanced Custom Fields plugin og trenger å få oversatt månedene som bare kommer på engelsk. Jeg skal benytte norsk, spansk, polsk og engelsk på nettsiden og bruker WPML til dette. Jeg har forandret datepicker eksempelvis d. MM yy på norsk og MM d, yy på engelsk for å har riktig visning av dato. Dette gjør jeg i ACF-plugin’ets kontrollpanel. Problemet er altså at MM alltid viser engelsk tekst. Jeg har prøvd å finne oversettelse på dette i WPML, men finner ikke måneden og oversettelsen i .mo-filene fungerer ikke til dette. Hovedspråket på nettsiden er på norsk – om det er viktig informasjon.

    Vet du hvordan jeg evt. gjør dette eller hvor jeg finner oversettelse på måneder? Jeg er egentlig ikke programmerer, så håper på et ikke-teknisk svar :)

    På forhånd takk!

    Reply
    1. PerS Post author

      Hei,

      Jeg har tatt kontakt med WPML for å bli med på de sitt Go-Global Program , kommer til å legge til WPML-støtte så snart jeg får WPML.

      I dages versjon av pluginet så blir navn på måned og dag blir hentet ut fra $wp_locale og ikke fra en .mo

      Reply
  39. Mark

    Hi there!

    Is there any way to use this date picker to create a reoccurring event?

    I’m using it to add dates to upcoming events on my website but some of these events occur weekly. At the moment I’m having to go into ever weekly event each week and change the date manually but as the number of weekly events increases it’s becoming a laborious task!

    If there isn’t, does anybody know a way I can get the data straight from the WP database? I’ve set each weekly events post category to “Regular-Event” so I’d need to export the date value for each post with this category, add 604800 seconds then re-import it. I’ve found the date values in the wp_postmeta table but cant figure out how to link this to the Post ID or Term ID!

    Any pointers in the right direction would be much appreciated! :)

    Reply
    1. PerS Post author

      You can get the value using get_field(), the syntax is:

      Reply
  40. Toni

    I’d like to see, that the WP timezone is used when you input and review dates and then save time as UTC like it’s now. This greatly enhances the UX and it’s suberb for developer to handle to date/time.

    If you want to avoid gestimation of WP set timezone give an option to choose the timezone.

    What do you think?

    Reply
  41. Vince

    I am trying to install the date/time picker and am having problems modifying the functions file to make it work. I keep getting an error when I insert the code you suggested into the functions.php file.
    This is the code I am inserting:
    add_action(‘acf/register_fields’, ‘my_register_fields’);
    function my_register_fields()
    {
    include_once(‘acf-date_time_picker/acf-date_time_picker.php’);
    }
    Where in the functions.php file do I need to insert?

    Is it correct that the reference ‘acf-date_time_picker/’ is to a folder in my themes/ifeaturepro/ directory…if so I have a folder named /themes/ifeaturepro5/acf-field-date-time-picker/ that does not match the folder reference in your suggested insert. Is this the cause of my problem?
    Your help would be greatly appreciated…thanks.

    Reply
    1. Per Søderlind Post author

      Just discovered that including the date and time picker in functions.php doesn’t work. For now, please add it as a plugin.

      Reply
  42. Bob

    hi there,

    great plugin! but:
    What could be the reason that the time format “HH:mm” does not work for me?
    Wordpress forget my 24-hour-format, instead next time I edit my “time”-field, shows me “hh:mm”

    thanks for any advice,
    Bob

    Reply
    1. Martijn

      I have the same issue.
      Date as d MM yy and Time as HH:mm
      Saving just clears the field.

      Also had issues saving in other formats, it’s was mixing up the year and months, entered 2014 as year and then it saved as 2020.

      Saving and displaying/using field as timestamp.

      Reply
  43. Joshua Michaels

    First, great Add-on – thank you!

    I’m having two issues:

    1) I have the date picker date set to yy-mm-dd and Save as Timestamp enabled. But I would like to format the date/time differently at certain locations in my plugin. It says to use the PHP date function but I’m not clear on exactly how to get the field value and then use that function. Can you give a quick example?

    For my purposes, in some places I would like to show the date as 2014-02-28 but in others February 28, 2014, etc.

    2) I’m using ACF in a plugin I’m creating and want to include the date time picker in my plugin (not in a theme). I copied the acf-date_time_picker folder to my plugin folder and I tried using this:

    but I cannot get it to work. It works as a standalone plugin but obviously I would like to include it directly.

    Reply
    1. Per Søderlind Post author

      Hi Joshua,

      1) When adding a date-and-time field, it you choose to “Get field as timestamp” you can do something like this:

      2) If you’d like to include my plugin in yours (and please feel free to do that), you should add the code from acf-date_time_picker.php to your plugin (i.e. not include acf-date_time_picker.php)

      Feel free to ask if you have any more questions.

      Reply
      1. Joshua Michaels

        Thanks Per, that worked perfectly. Just offhand, do you know a way to show lowercase am or pm on a Mac? %P is not supported.

        Will add the code to my plugin and see how that goes.

        Thanks for the help!

        J

        Reply
        1. Joshua Michaels

          If anyone is looking, using Per’s code above to format your datetime:

          would result in: Tuesday, February 25, 2014

          would result in: 5:49pm

          Reply
        2. Per Søderlind Post author

          I was a bit quick (and tired) when I answered. You should use the WordPress function date_i18n as in

          for lower case am/pm, use “a”

          Reply
  44. Joshua Michaels

    Trying to only show posts from today or in the future using the date picker. Below is my loop arguments but with this it only shows all event posts (in past and future). What am I missing here?

    Reply
  45. Frank

    Hey there! Really nice plugin.

    I have several fields on my site that use the “Time Picker” option, and looking in the database, I’m confused as to what format these are being saved in.

    I get a value like: 1392591600
    Which, assuming it’s a timestamp, converts to Sun, 16 Feb 2014 23:00:00 GMT

    The thing is, this field should only be a time, not a date as well, right? I need to access the value directly from the database (i.e. can’t use PHP), and convert to a readable time, and I’m unsure how to parse this without PHP.

    Reply
    1. Per Søderlind Post author

      Hi Frank,

      You have two option, either save the time as a string (select “No” to save as timestamp when you create the field) or as a timestamp.

      A timestamp (number of seconds since 1/1/1970) will contain a date. If your field is a time field, todays date will be added. You can convert the timestamp to a time value in MySQL using something like this:

      Reply
  46. Melissa

    Hey there. This seems like exactly what I’ve been looking for. However, I’m having problems getting the date picker to show up as an option in the field type drop down. I’ve tried installing this add-on using both the regular plugin install and the include options, and neither seems to work. After install, the add-on is listed as installed in the “Add-Ons” section under “Custom Fields”, but when I drop down the field types when creating a custom field, it’s not listed as an option. I installed the debugging/list enqueued scripts plugin, and it’s displaying all expected scripts. Any suggestions? Thanks for your help!

    Reply
  47. Mat Doidge

    Hi there,

    I’m having problems formatting the date from a date + time picker. So far I’ve tried:


    $field = get_field("gig_datetime");
    echo date_i18n('d-m-y', $field);

    But this doesn’t get any values from the plugin and instead just uses todays date. I’m confused!

    Reply
    1. Per Søderlind Post author

      When you created the field, did you choose “Get field as timestamp”? Please see my example above.

      Also, what’s $field returning? ( echo $field;)

      Reply
      1. Mat Doidge

        Yeh that’s what’s got me confused. Yep it’s set to save field as timestamp and get field as timestamp. If i used echo $field; in my loop, I get nothing. Does that mean it’s not getting the field correctly?

        Reply
        1. Per Søderlind Post author

          Yes, try to use the post_id, as in my simple example.

          Your loop is in a single post ? If not, you’ll have to use the post_id. If it’s in a single post, the post you’re testing on has it a date-time value saved?

          Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">