Support

Account

Home Forums Search Search Results for 'date picker'

Search Results for 'date picker'

reply

  • Hi @elliot,

    Here is the data from ‘postmeta’ table.

    a:11:{s:3:"key";s:19:"field_51f95d72c7c5a";s:5:"label";s:4:"Date";s:4:"name";s:4:"date";s:4:"type";s:11:"date_picker";s:12:"instructions";s:36:"Please select the date of your event";s:8:"required";s:1:"0";s:11:"date_format";s:3:"Ymd";s:14:"display_format";s:8:"dd/mm/yy";s:9:"first_day";s:1:"1";s:17:"conditional_logic";a:3:{s:6:"status";s:1:"1";s:5:"rules";a:1:{i:0;a:3:{s:5:"field";s:19:"field_51f846266fda1";s:8:"operator";s:2:"==";s:5:"value";s:6:"Events";}}s:8:"allorany";s:3:"all";}s:8:"order_no";i:4;}

  • Hi @kikimarie1234

    Have you debugged the variables in each step?
    Can you post the results?

  • Try this:

     list($day, $month, $year) = sscanf('12/04/2010', '%02d/%02d/%04d'); // field value
    $datetime = new DateTime("$year-$month-$day"); // your format
    echo $datetime->format('r'); // desired format
    

    source: http://stackoverflow.com/questions/2621433/date-create-from-format-equivalent-for-php-5-2-or-lower

  • I am having the same problem as well.

    I’m using the following code in my theme functions file

    function datepicker_to_unix( $date ){
    	$dateparts = explode('/', $date);
    	$unixtimestamp = strtotime(date('d.m.Y', strtotime($dateparts[1].'/'.$dateparts[2].'/'.$dateparts[0])));
    	return $unixtimestamp;
    }

    And then the following in my template file

    <?php $date = get_field('field_name'); echo date('F d, Y', datepicker_to_unix($date )); ?>
    

    The result outputs: January 01, 1970

  • Thank you SO much! This is what I ended up with…

    <div>
    		
    		<?php $associations = get_field('associations');
    		if( $associations ): ?>
    		
    		<?php foreach( $associations as $association): ?>
    			<?php 
    			$photo = get_field('investment_logo', $association->ID); ?>
    					
    			<a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark">
    			<img src="<?php echo $photo['url']; ?>" alt="<?php echo $photo['alt']; ?>" />
    			</a>
    			
    		<?php endforeach; ?>
    
    		<?php endif; ?>
    
    		<a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark" >
    		<?php the_title(); ?></a>
    
    		<em><?php the_field('publication_source'); ?></em>
    
    		<span><?php $date = get_field('publication_date'); echo date('F d, Y', datepicker_to_unix($date )); ?></span>
    
    		</div>

    Really appreciate your quick response! Thank you!!

  • Hi @sallywp

    What code are you using to display the date field data?

  • Hi @kikimarie1234

    Thanks for the screenshots.

    The code you want to use will look something like this:

    
    <div>
    		
    	<a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark" ><?php the_title(); ?></a>
    
    	<em><?php the_field('publication_source'); ?></em>
    
    	<span><?php $date = get_field('publication_date'); echo date('F d, Y', datepicker_to_unix($date )); ?></span>
    	
    	<?php 
    	
    	// 1. Get all the relationship values
    	$associations = get_field('associations');
    	
    	
    	// 2. Make sure a value exists
    	if( $associations ): ?>
    		
    		<?php 
    		
    		// 3. loop through relatinoship values
    		foreach( $associations as $association): ?>
    			
    			<?php // 4. Load the image field from the association ?>
    			<img src="<?php echo get_field('investment_logo', $association->ID); ?>" />
    			
    		<?php endforeach; ?>
    
    	<?php endif; ?>
    </div>
    

    Please note this is an example and not the final Markup you will need.

    Thanks
    E

  • Yes, I am aware that I need to put the relationship code within my loop but I don’t know what the code should be. Every time I tried adding it, I got a php error. I’m confused because I’m already querying multiple different posts on the page (unlike the documentation which shows an example of querying for a single template file).

    Please see the screenshots for what I’m working with. I know this is slightly complicated but I’m sure folks would want to know how to do this as well.

    I want to query the image somewhere between this div.

    <div>
    		
    <a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark" ><?php the_title(); ?></a>
    
    		<em><?php the_field('publication_source'); ?></em>
    
    <span><?php $date = get_field('publication_date');
    			echo date('F d, Y', datepicker_to_unix($date )); ?></span>
    		</div>

    Really appreciate your help! Thank you!!

  • Hi @rcriche

    1. Please look over the documentation for examples of formatting a date field:
    http://www.advancedcustomfields.com/resources/field-types/date-picker/

    2. You can use a PHP function such as substr

  • @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>';
    		}	 	 			 	 
    ?>
  • This reply has been marked as private.
  • 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

  • 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;
    }
    
  • @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

  • ok i found alone,
    i don’t put the good key name šŸ˜‰

    it’s ok like this:

    $currentdate = date(“Y-m-d”,mktime(0,0,0,date(“m”),date(“d”)-1,date(“Y”)));

    query_posts( array(
    ‘meta_query’=> array(
    array(
    ‘key’ => ‘date-picker’,
    ‘compare’ => ‘>’,
    ‘value’ => $currentdate,
    ‘type’ => ‘DATE’,
    )),
    ‘post_type’ => ‘concerts’,
    ‘meta_key’ => ‘date-picker’,
    ‘orderby’ => ‘meta_value_num’,
    ‘posts_per_page’ => 4,
    ‘order’ => ‘ASC’,
    ) );
    ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class=”post-photo”>
    <div class=”thumbnail opacity”>”><?php the_post_thumbnail(‘thumbnail’); ?></div>
    <p><?php the_title();?></p><br/>
    <div class=”bouton-6″>voir l’album</div>
    </div>
    <?php endwhile; ?>
    <?php endif; ?>
    <?php wp_reset_query(); ?>

  • Hi @cerulean

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

    Have you done any debugging?

  • 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!

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

  • 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.

  • 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!

  • Got this working like this:

    <?
    				
    				$currentdate = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
    				
                    if ( get_query_var('paged') ) {
                      $paged = get_query_var('paged');
                      } else if ( get_query_var('page') ) {
                              $paged = get_query_var('page');
                      } else {
                              $paged = 1;
                      }
                      query_posts( array(
                      	'meta_query'=> array(
    	                    array(
    	                      'key' => 'event_date',
    	                      'compare' => '>',
    	                      'value' => $currentdate,
    	                      'type' => 'DATE',
    	                    )),
    	                 'post_type' => 'events',
    	                 'meta_key' => 'event_date',
    	                 'orderby' => 'meta_value_num',
    	                 'posts_per_page' => 4,
    	                 'order' => 'ASC',
    	                 'paged' => $paged ) );
                      while (have_posts()) : the_post();
                    ?>
  • I’m having this same issue, trying to get the date to automatically display formatted like “Mon July, 29”.

    If I use the code above, it breaks the page and nothing will load. Any thoughts on this? I love this plugin by the way!

    Here is the code that I’m using. The “onsale” field is the Date Picker and I would like to reformat how it displays on the page. Thanks!

    <?php
    $onsale_date = strtotime(get_field(‘onsale’));
    $now = time();

    if ($onsale_date > $now) {
    ?>
    On Sale

    <?php
    echo get_field( ‘onsale’ );
    }
    else { echo get_field( ‘price’ );
    }
    ?>

  • 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

  • save_post() works fine in 4.1.8, and doesn’t create any errors. Here’s XDebug Context for ACF 4.1.8 , breakpoint at $f = apply_filters('acf/load_field', false, $k ); in acf.php:save_post( $post_id )

    Inside the loop, 1st iteration (single date and time picker field):

    
    $f = array[18]
    	$f['name'] = (string) dato
    	$f['class'] = (string) date_time_picker
    	$f['time_format'] = (string) H:mm
    	$f['field_group'] = (int) 6583
    	$f['conditional_logic'] = array[3]
    		$f['conditional_logic']['allorany'] = (string) all
    		$f['conditional_logic']['rules'] = array[1]
    			$f['conditional_logic']['rules'][0] = array[2]
    				$f['conditional_logic']['rules'][0]['operator'] = (string) ==
    				$f['conditional_logic']['rules'][0]['field'] = (string) null
    		$f['conditional_logic']['status'] = (int) 0
    	$f['show_week_number'] = (string) false
    	$f['value'] = <string>
    	$f['required'] = (int) 0
    	$f['type'] = (string) date_time_picker
    	$f['id'] = (string) acf-field-dato
    	$f['key'] = (string) field_51d520b7091da
    	$f['label'] = (string) dato
    	$f['picker'] = (string) slider
    	$f['show_date'] = (string) true
    	$f['order_no'] = (int) 0
    	$f['instructions'] = <string>
    	$f['save_as_timestamp'] = (string) true
    	$f['date_format'] = (string) m/d/y
    $v = (string) 7/11/13 7:00
    $post_id = (int) 6640
    $k = (string) field_51d520b7091da
    $this = Acf[1]
    	$this->settings = array[5]
    		$this->settings['path'] = (string) /Users/per/Sites/dev.local/wp-content/plugins/advanced-custom-fields/
    		$this->settings['dir'] = (string) http://dev.local/wp-content/plugins/advanced-custom-fields/
    		$this->settings['upgrade_version'] = (string) 3.4.1
    		$this->settings['hook'] = (string) advanced-custom-fields/acf.php
    		$this->settings['version'] = (string) 4.1.8
    

    Second iteration, date and timepicker field inside a repeater field

    
    $f = array[16]
    	$f['name'] = (string) repeat
    	$f['class'] = (string) repeater
    	$f['field_group'] = (int) 6583
    	$f['conditional_logic'] = array[3]
    		$f['conditional_logic']['allorany'] = (string) all
    		$f['conditional_logic']['rules'] = array[1]
    			$f['conditional_logic']['rules'][0] = array[3]
    				$f['conditional_logic']['rules'][0]['operator'] = (string) ==
    				$f['conditional_logic']['rules'][0]['field'] = (string) null
    				$f['conditional_logic']['rules'][0]['value'] = <string>
    		$f['conditional_logic']['status'] = (int) 0
    	$f['layout'] = (string) table
    	$f['row_min'] = (int) 0
    	$f['button_label'] = (string) Add Row
    	$f['sub_fields'] = array[1]
    		$f['sub_fields'][0] = array[18]
    			$f['sub_fields'][0]['label'] = (string) dato2
    			$f['sub_fields'][0]['name'] = (string) dato2
    			$f['sub_fields'][0]['value'] = <string>
    			$f['sub_fields'][0]['key'] = (string) field_51da7b24dbf9a
    			$f['sub_fields'][0]['instructions'] = <string>
    			$f['sub_fields'][0]['save_as_timestamp'] = (string) true
    			$f['sub_fields'][0]['column_width'] = <string>
    			$f['sub_fields'][0]['order_no'] = (int) 0
    			$f['sub_fields'][0]['id'] = (string) acf-field-dato2
    			$f['sub_fields'][0]['picker'] = (string) slider
    			$f['sub_fields'][0]['class'] = (string) date_time_picker
    			$f['sub_fields'][0]['time_format'] = (string) h:mm tt
    			$f['sub_fields'][0]['type'] = (string) date_time_picker
    			$f['sub_fields'][0]['show_week_number'] = (string) false
    			$f['sub_fields'][0]['show_date'] = (string) true
    			$f['sub_fields'][0]['required'] = (int) 0
    			$f['sub_fields'][0]['date_format'] = (string) m/d/y
    			$f['sub_fields'][0]['conditional_logic'] = array[3]
    				$f['sub_fields'][0]['conditional_logic']['status'] = (int) 0
    				$f['sub_fields'][0]['conditional_logic']['rules'] = (int) 0
    				$f['sub_fields'][0]['conditional_logic']['allorany'] = (string) all
    	$f['required'] = (int) 0
    	$f['type'] = (string) repeater
    	$f['id'] = (string) acf-field-repeat
    	$f['key'] = (string) field_51da7b12dbf99
    	$f['label'] = (string) repeat
    	$f['order_no'] = (int) 1
    	$f['instructions'] = <string>
    	$f['row_limit'] = <string>
    $v = array[2]
    	$v['acfcloneindex'] = array[1]
    		$v['acfcloneindex']['field_51da7b24dbf9a'] = <string>
    	$v[1373458984969] = array[1]
    		$v[1373458984969]['field_51da7b24dbf9a'] = (string) 7/12/13 12:00 am
    $post_id = (int) 6640
    $k = (string) field_51da7b12dbf99
    $this = Acf[1]
    	$this->settings = array[5]
    		$this->settings['path'] = (string) /Users/per/Sites/dev.local/wp-content/plugins/advanced-custom-fields/
    		$this->settings['dir'] = (string) http://dev.local/wp-content/plugins/advanced-custom-fields/
    		$this->settings['upgrade_version'] = (string) 3.4.1
    		$this->settings['hook'] = (string) advanced-custom-fields/acf.php
    		$this->settings['version'] = (string) 4.1.8
    
    

    But I guess this is not really the issue. As said previously, the content exist in post meta but it’s not displayed/populated to the custom field.

    When I open a post, where (in ACF) is data read from post meta (ie, where should I set my breakpoints)?

  • In addition to Elliot’s suggested method, if you didn’t want to change the value saved to the database, you could use the DateTime ‘format’ method:

    
    $date = get_field("my_date_field");
    
    // assuming your return format is "Ymd"
    $dateTime = DateTime::createFromFormat("Ymd", $date);
    
    if ( is_object($dateTime) ) {
      $month = $dateTime->format('F');
      $year = $dateTime->format('Y');
      //...
    }
    
Viewing 25 results - 751 through 775 (of 784 total)