0

I am using below code to display advanced custom field (date fields) in wordpress. I want two dates to appear like e.g 12 mar - 15 mar 2017.

I am using this code

<?php echo the_sub_field('start_date').' - '.the_sub_field('end_date'); ?>

How to do it please explain ?

Right now I am getting result like this 18/09/201722/09/2017 -

my full html code

<table style=" border-collapse: collapse; table-layout: fixed; width: 800px;">
                      <tbody>
                      <tr>
        <td style="border: 1px solid #ddd;"><h5 style="color:#044970;">Refernce</h5></td>
        <td style="border: 1px solid #ddd;"><h5 style="color:#044970;">Dates</h5></td>
        <td style="border: 1px solid #ddd;"><h5 style="color:#044970;">Venue</h5></td>
        <td style="border: 1px solid #ddd;"><h5 style="color:#044970;">Fees</h5></td>
        <td style="border: 1px solid #ddd;"><h5 style="color:#044970;">CPE Credits</h5></td>
        <td style="border: 1px solid #ddd;"><h5 style="color:#044970;">Regsitrations</h5></td>
        </tr>
</tbody>
</table>




   <table style=" border-collapse: collapse; table-layout: fixed; width: 800px;">
                      <tbody>

               <?php 

if( have_rows('sub_seminars') ):

    while( have_rows('sub_seminars') ) : the_row(); 

        ?>



        <tr>
        <td style="border: 1px solid #ddd;"><h6><?php the_sub_field('ref'); ?></h6></td>
        <td style="border: 1px solid #ddd;"><h6><?php echo the_sub_field('start_date').' - '.the_sub_field('end_date'); ?></h6></td>
        <td style="border: 1px solid #ddd;"><h6><?php the_sub_field('venue'); ?></h6></td>
        <td style="border: 1px solid #ddd;"><h6><?php the_sub_field('fees'); ?></h6></td>
        <td style="border: 1px solid #ddd;"><h6><?php the_sub_field('cpe_credits'); ?></h6></td>
        <td style="border: 1px solid #ddd;"><a href="<?php home_url(); ?>/euromatechnew/seminar-registrations?seminartitle=<?php echo htmlentities(urlencode(get_the_title())) ?>&amp;seminarvenue=<?php echo the_sub_field('venue'); 
             ?>&amp;seminardates=<?php echo the_sub_field('start_date').the_sub_field('end_date'); ?>&amp;seminarref=<?php echo the_sub_field('ref') ?>" class="dt-btn" style="margin: 3px 0px 0px 0px">Register Now</a></td>
        </tr>


        <?php

    endwhile;

         endif;

        ?>




                     </tbody>
        </table>
Damon
  • 135
  • 13

1 Answers1

2

the_sub_field function already echoes data.

To get data and then echo it - use get_sub_field.

Proper code is:

<?php echo get_sub_field('start_date').' - '.get_sub_field('end_date'); ?>

Or as with your markup:

<td style="border: 1px solid #ddd;"><h6><?php the_sub_field('start_date');?> - <?php the_sub_field('end_date');?></h6></td>

To format your dates as you need you can use date fomatting functions of php, e.g date.

u_mulder
  • 54,101
  • 5
  • 48
  • 64
  • Did the trick for me. But how to display Date as "d m - d m Y" i.e Fetch Day and Month from Start Date and append before Day, Month and Year of end Date – Damon Feb 27 '17 at 07:46
  • As date returned from `get_sub_field` is a simple date string - you can use any date formatting functions that you like. Question to start is here http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php – u_mulder Feb 27 '17 at 07:49