0

In my table currently shows 2019-01-21 this format and i want to show 21-01-2019 like this

I am trying like this

<table>
<tr>
 <th>DOB</th>
</tr>

 <?php foreach($employees as $post){?>
 <tr>
 <td><?php echo $post->user_date_of_birth;?></td>
 </tr>
 <?php }?>
</table>

8 Answers8

1
    Please set format in sql like this.

    SELECT FORMAT(FieldName,'dd-MM-yyyy')
Hemang A
  • 1,012
  • 1
  • 5
  • 16
1

Okay, so let's assume that the user_date_of_birth has a value of 2019-01-21

Let's use your code:

<table>
    <tr>
      <th>DOB</th>
    </tr>

    <?php foreach($employees as $post){?>
    <tr>
      <td><?php echo date("d-m-Y", strtotime($post->user_date_of_birth));?></td>
    </tr>
    <?php }?>
</table>

Hope this helps!

Smithiam
  • 162
  • 1
  • 16
Roshan
  • 786
  • 1
  • 9
  • 20
0
 echo date('d-m-y', strtotime($post->user_date_of_birth));
Eiji
  • 454
  • 6
  • 15
0

You can use the following code

<?php
    $yourDate = "2019-01-21";
    echo date("d-m-Y", strtotime($yourDate) );
?>

Output: 21-01-2019

Then your final code will be like this

<table>
<tr>
 <th>DOB</th>
</tr>

 <?php foreach($employees as $post){?>
 <tr>
 <td><?php echo date("d-m-Y", strtotime($post->user_date_of_birth));?></td>
 </tr>
 <?php }?>
</table>
Ankur Tiwari
  • 2,762
  • 2
  • 23
  • 40
0

<td><?php echo date('d-m-Y', strtotime($post->user_date_of_birth));?></td>

CHATHURA
  • 106
  • 7
0

Try this

<td><?php echo date('d-m-Y', strtotime($post->user_date_of_birth));?></td>

Read more date() and strtotime()

Danish Ali
  • 2,354
  • 3
  • 15
  • 26
0
<table>
<tr>
 <th>DOB</th>
</tr>

 <?php foreach($employees as $post){ 
 $datetime=$post->user_date_of_birth;
        $timeformat = date("d-m-Y",strtotime($datetime));   ?>
 <tr>
 <td><?php echo $timeformat; ?></td>
 </tr>
 <?php }?>
</table>
Maruthi Prasad
  • 170
  • 1
  • 12
0

you should to manage this in programming side, like `$origDate = "2018-04-20";

$newDate = date("d-m-Y", strtotime($origDate));
echo $newDate;`
Mohammad Malek
  • 624
  • 1
  • 7
  • 17