+ 1
How to display the date in appropriate format in PHP?
<?php if(isset($_POST['submit'])){ echo date_format($_POST['selected_date'], 'd/m/y'); } ?> <html> <form method="post"> <input type="date" name="selected_date" dataformatas="dd-mm-yyyy"/> <br/> <input type="submit" name="submit" value="Convert" /> </form> </html>
1 Respuesta
+ 1
You should delete ' dataformatas="dd-mm-yyyy" ' from your input tag. This is not valid.
A <input> tag will always store a date like (dd-mm-yyyy).
To change the format in PHP you can use this:
$date = $_POST['date'];
$newFormat = date("d-m-Y", strtotime($date));
For further information, have a look at https://secure.php.net/manual/en/function.date.php