-2

$start_date and $end_date are dates, but they need a D/M/Y format. How can i echo it as that format?

<?php
foreach($wp_trips as $wp_trip){
  if($is_day_trip){
    echo '<li>' .  $wp_trip->start_date . '</li>';                                        
  } else {
    echo '<li>' .  $wp_trip->start_date . ' t/m ' . $wp_trip->end_date . '</li>');
  }
} 
?>
brombeer
  • 8,716
  • 5
  • 21
  • 27
Michael
  • 47
  • 9
  • 1
    Possible duplicate of [Convert date format yyyy-mm-dd => dd-mm-yyyy](https://stackoverflow.com/questions/2487921/convert-date-format-yyyy-mm-dd-dd-mm-yyyy) – treyBake Oct 31 '18 at 12:55
  • 1
    Possible duplicate of [Convert one date format into another in PHP](https://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – Elias Soares Oct 31 '18 at 12:59

4 Answers4

2

Michael try this:

$originalDate = $wp_trip->start_date;
$newDate = date("d-m-Y", strtotime($originalDate));
treyBake
  • 6,440
  • 6
  • 26
  • 57
0

For example you had date format like this

$trip = '2018-10-31 00:00:00'; //Sample Date Format

$newFormat = date('d M Y',strtotime($trip));
echo $newFormat;

Out put should be 31 Oct 2018.

Here full documentation of date formats : http://php.net/manual/en/function.date.php

Bayu Dwiyan Satria
  • 986
  • 12
  • 28
0
echo '<li>'. date('D/M/Y', strtotime($wp_trip->start_date)).'</li>';

You have to use strtotime

Vpa
  • 703
  • 2
  • 9
  • 30
0

Using strtotime() to convert your time string into time stamp and then using PHP date() function to output your desired format:

echo date("d/M/Y", strtotime($wp_trip->start_date));
treyBake
  • 6,440
  • 6
  • 26
  • 57
Osama Ibrahim
  • 148
  • 10