-1

The below code displays date in yyyy-mm-dd

 <td>
<?php 
echo($data['Date']);?></td> 
  <td>

I want it in mm-dd-yyyy

2

3 Answers 3

0

Try this

Use strtotime($data['Date']) to convert string to date time

and the use date('m-d-Y',strtotime($data['Date'])) to format it to your requirement

<td>
<?php echo date('m-d-Y',strtotime($data['Date']));?>
</td>
0
$originalDate = "2010-03-21"; 
$newDate = date("m-d-Y", strtotime($originalDate));
0
$s_date = $_POST['your_date_field'] // your date variable in  '2015-10-10 ' formate
echo date('m-d-Y',strtotime($s_date)) // return 10-10-2015
2
  • 1
    its displying like 01-01-1970
    – User
    Jul 6, 2015 at 5:53
  • 1
    check your $)POST field if $_POST is null then it will display 01-01-1970 otherwise it will convert date ....
    – Affan
    Aug 19, 2015 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.