Support

Account

Forum Replies Created

  • For anyone else wondering …

    I needed to show long decimal latitude and longitude values (e.g. 53.234567) to 2dps on the front end (53.23).

    This worked for me.

    <?php
    
    	$output = get_field('latitude_metric');
    	$latitude = round($output, 2);
    	echo $latitude;
    ?>

    Hope it’s of use.

  • Elliot

    No I haven’t used yymmdd as we need the day of the week to show too. Can I, using the entered data (DyyMd), “reconstruct” it as yymmdd and use that in the get_posts function?

    Code now

    <?php 
     
    		$date = get_field('course_date');
    		// $date = WED2013NOV6 (23/11/1988)
     
    		// extract Y,M,D
    		$D = substr($date, 0, 3);
    		$y = substr($date, 3, 4);
    		$m = substr($date, 7, 3);
    		$d = substr($date, 10, 2);
    		
     
    		// create UNIX
    		$time = strtotime("{$d}-{$m}-{$y}");
     
    		// format date (23/11/1988)
    	 
    		?>
    		<div class="calendar">
    		<p class="calendarDate"><span class="dow"><?php echo $D; ?></span>
    			<span class="day"><?php echo $d; ?> <br /><?php echo $m; ?></span>
    			<span class="year"><?php echo $y; ?></span>
    			</p>
    			</div>

    Cheers

    Pete

  • Elliott

    How often does this happen…

    Solution found

    <?php 
     
    		$date = get_field('course_date');
    		// $date = WED2013NOV6 (23/11/1988)
     
    		// extract Y,M,D
    		$D = substr($date, 0, 3);
    		$y = substr($date, 3, 4);
    		$m = substr($date, 7, 3);
    		$d = substr($date, 10, 2);
    		
     
    		// create UNIX
    		$time = strtotime("{$d}-{$m}-{$y}");
     
    		// format date (23/11/1988)
    	 
    		?>
    		<div class="calendar">
    		<p class="calendarDate"><span class="dow"><?php echo $D; ?></span>
    			<span class="day"><?php echo $d; ?> <br /><?php echo $m; ?></span>
    			<span class="year"><?php echo $y; ?></span>
    			</p>
    			</div>

    Outputs as I wish and all hunky-dory… just a final one… with the date format now saved as WED2013NOV6 … can I wort the courses into a dater ordered list? Or are you going to tell me to read the docs 🙂

    Pete

  • Elliot

    Ok have found a bit of time to try and get my head round extracting elements of the date picker value.

    However this code

    <?php 
     
    	$date = get_field('course_date');
    	// $date = 19881123 (23/11/1988)
     
    	// extract Y,M,D
    	$y = substr($date, 0, 4);
    	$m = substr($date, 4, 2);
    	$d = substr($date, 6, 2);
     
    	// create UNIX
    	$time = strtotime("{$d}-{$m}-{$y}");
     
    	// format date (23/11/1988)
    	 
    	?>
    	<div class="calendar">
    	<p class="calendarDate"><span class="dow"><?php echo date('D' ); ?></span>
    		<span class="day"><?php echo date('d'); ?> <br /><?php echo date('M'); ?></span>
    		<span class="year"><?php echo date('Y'); ?></span>
    		</p>
    		</div>

    Outputs today’s date and not the date entered via Date Picker whose Field name is course_date.

    If I used the code on http://www.advancedcustomfields.com/resources/field-types/date-picker/ I get the 1st Jan 1970 outputted.

    A steer in the right direction would be a lifesaver. php version is 5.2.17

    Website: http://tideswellschooloffood.co.uk

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