Support

Account

Home Forums General Issues Datepicker: wrong format is displaying

Solving

Datepicker: wrong format is displaying

  • I have set up a datepicker field and am displaying it via a template using get_field(name) but the date format is wrong. I have “yymmdd” entered for “save format” and “MM d, yy” for “display format”. Unfortunately what is displaying is the “save format”.

    How can I get the “display format” to properly appear?

  • Hi @cerulean

    The display_format is only for use in the back-end. It is not what is returned to you via the API.

    To format the date object, please follow the code examples on the date picker documentation page.

    Thanks
    Elliot

  • Sorry but I’m not having luck with getting the date formatting to work, referring to the datepicker documentation page.

    http://www.advancedcustomfields.com/resources/field-types/date-picker/

    Here’s my code:

    if(get_field('deadline'))
    	{
    	echo '<li><strong>Deadline: </strong>' . get_field('deadline') . '</li>';
    	}	

    I was trying this but end up with a blank page:

    if(get_field('deadline'))
    	{
            $date = DateTime::createFromFormat('Ymd', get_field('deadline'));
    	echo '<li><strong>Deadline: </strong>' . $date->format('d-m-Y') . '</li>';
    	}	

    Thanks for any help!

  • Unrelated but odd … when I try to use the “link” tool in the WYSIWYG editor it shuts the entire site window after clicking the link window button (tried it a few times). Not sure if anyone else has this problem but thought I’d mention it.

  • To be clear, I’m referring to the WYSIWYG editor on this forum site. Anyway, thanks for helping with my date formatting problem : )

  • Thanks for any assistance on displaying the Datepicker date as July 19, 2013 and not 20130719.

    Let me know if there’s other documentation I should be looking at besides http://www.advancedcustomfields.com/resources/field-types/date-picker/

    Thanks!

  • Hi @cerulean

    Perhaps you could elaborate more on ‘Sorry but I’m not having luck’.

    Have you done any debugging?

  • @cerulean
    I’m having the same problem…using the code provided in the Date Picker docs but still coming up with “20131111” as a display format, for example.

    Your code above looks fine to me; it’s very similar to what I’ve been trying. Did you have any luck finding a solution?

    M

  • Hey guys,

    Have you debugged your code to see what is and isn’t working?

    eg:

    
    if(get_field('deadline'))
    {
        $date = DateTime::createFromFormat('Ymd', get_field('deadline'));
        
        echo '<pre>';
        	print_r($date);
        echo '</pre>';
        die;
    }
    
  • Hello, guys,

    I thought that my issue involved the PHP version my server had installed. I asked the host to upgrade me to 5.3 at least.

    This upgrade worked…spottily. I could then get the format to change, mostly, but then I started having issues with the custom fields themselves; I would use the datepicker to choose a date, update the post, and the date would disappear. I would also get a fatal error: “Call to a member function format() on a non-object” on the posts that did have dates attached to the field. When I was lucky, the formats were changed perfectly (using the PHP code suggested on the DatePicker reference page on this site), but in the end I had to set the field to “text” instead of “datepicker” because I couldn’t guarantee success.


    @cerulean
    or others like him/her – I’d definitely check to see what version of PHP your server is running. If it’s below 5.3 the “DateTime::createFromFormat” code won’t work. Upgrade and it might fix your issue!


    @elliot
    , or others – can you point me to a piece of jQuery that you know works to change the datepicker format? And perhaps let me know what I need installed on my site as well (jQuery, jQuery UI, perhaps)?

    Many thanks, Matt

  • @matthewbivins sorry for the late reply, just got back in town. Here’s the code that worked for me. It can be improved upon but did the job. Best of luck.

    <?php 
    	if(get_field('deadline'))
    		{
    			$date = DateTime::createFromFormat('Ymd', get_field('deadline'));
    			echo '<li><strong>Deadline: </strong>';
    			echo $date->format('F j, Y');
    			echo '</li>';
    		}	 	 			 	 
    ?>
  • Hey Guys, old topic, but I have the same problem.I always get something like 20131111 and not what is expected…

    My PHP Version is 5.6.19

    That’s what I get when debugging:

    DateTime Object
    (
        [date] => 2016-05-27 21:47:17.000000
        [timezone_type] => 3
        [timezone] => UTC
    )

    I can’t go with cerulean’s solution because then the date output is all english what I get – instead of german, what I would need.

    Any ideas??

Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘Datepicker: wrong format is displaying’ is closed to new replies.