1

I created a web form using PHP. In this form there is a field with input type "date" where I want to change the format of said date. But when I change the attribute it's not working.

<input type="date" value="<?php echo date('Y-m-d');?>"/> 

When I change it into

<input type="date" value="<?php echo date('d-M-y');?>"/>

It's not working. I want to display my date as date

How I can do it?

<form action="" method="POST" enctype="multipart/form-data">
<?php echo'MB | Falcons | '  ?> 
<?php echo date("d M"); ?>
    <table width="664" >
    <tr>
        <td height="34"  colspan="6" class="DivSubHeaderCellTop"><p>  Morning Breifing</p></td>
</tr>
    
    <tr>
        <td  colspan="6" class="DivSubHeaderCellTop">Upload File</td>
</tr>
<tr><td>&nbsp;</td> <td>   MB | Falcons</td> <td width="154"><input type="date" value="<?php echo date('Y-m-d');?>"/> </td>
 </tr>
    <tr> <td width="157" height="23">&nbsp;</td> </tr>
    <tr>
    <td colspan="4" bordercolorlight="#006666">  <input type="file" name="files[]"  multiple/> </td>
    <td width="215">
      <input type="submit"/>
   </td>
    <tr>
    <td height="75">
    </td>
    <td width="116">
    
   </td> </tr>
    </table>
</form>
TylerH
  • 20,799
  • 66
  • 75
  • 101
sunny
  • 1,511
  • 5
  • 20
  • 57
  • have you read documentation of this date-picker js? you will get answer in this documentation...you need to set format using jquery/javascript – Prafulla Jun 24 '15 at 05:54
  • 1
    As I believe it's a more datepicker jquery question, please read: http://api.jqueryui.com/datepicker/#option-dateFormat `$( ".selector" ).datepicker({ dateFormat: "yy-mm-dd" });` – Ofir Baruch Jun 24 '15 at 05:54
  • @Prafulla you mean i use Jquery or Javascript? – sunny Jun 24 '15 at 05:55
  • @Uchiha am using HTNL5 – sunny Jun 24 '15 at 05:57
  • @OfirBaruch Can i use it in Input Type="date" or not? – sunny Jun 24 '15 at 05:59
  • refer this link [http://stackoverflow.com/questions/7372038/is-there-any-way-to-change-input-type-date-format](http://stackoverflow.com/questions/7372038/is-there-any-way-to-change-input-type-date-format).. – Prafulla Jun 24 '15 at 06:00

3 Answers3

1

Your php date function is fine. The problem is that you need to define that format also with your datepicker settings.

Update: Just noticed that you're using the HTML5 feature which according to the manual doesn't allow date format modifications. Consider using the jquery ui plugin and follow the instructions below. (Consider also reading about jquery ui if you're not already familiar with it)

According to the jquery ui datepicker docs, you should set the format like that:

$( ".selector" ).datepicker({
  dateFormat: "yy-mm-dd"
});

You can see the possible date formats here: Date Format

In case you want '24-Jun-15', you can use the following:

$( ".selector" ).datepicker({
  dateFormat: "dd-M-y"
});

You might wish to replace dd with d for no leading zeroes.

Ofir Baruch
  • 10,323
  • 2
  • 26
  • 39
  • Ofir Baruch Thank you so much. Just please tell me how i can use it? can i use it into Input type or seprate? – sunny Jun 24 '15 at 06:01
  • please i need some more help of you. please see above my code and tell me where i put this jquery code? – sunny Jun 24 '15 at 06:07
  • 1
    This is the tutorial that would help you: http://learn.jquery.com/jquery-ui/getting-started/ – Ofir Baruch Jun 24 '15 at 06:14
0
echo date('dd ([ \t.-])* m ([ \t.-])* y h:i:s A');

output like "30-June 2008"

Or refer date format manual

Mahesh Shukla
  • 186
  • 10
0

You can change date format using php as example below

$original = "2010-03-21";
$new = date("d-M-Y", strtotime($original));

and put variable $new to your input tag as

 <input type="date" value="<?php echo date('d-M-y');?>"/>

hope your problem will going to resolve by this.

Uday
  • 9
  • 2