'How to set date format like (24-Jun-15) with a calendar?
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

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> </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"> </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>
Solution 1:[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.
Solution 2:[2]
echo date('dd ([ \t.-])* m ([ \t.-])* y h:i:s A');
output like "30-June 2008"
Or refer date format manual
Solution 3:[3]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Mahesh Shukla |
| Solution 3 | Uday |
