0

With the html input date

<p class="time">Reisezeitraum:
<input type="date" id="date1" name="date1">-<input type="date" id="date2" name="date2">
</p>

I get this date output by email with the following PHP code:

$date1 = htmlspecialchars($_POST["date1"], ENT_QUOTES, "UTF-8");
$date2 = htmlspecialchars($_POST["date2"], ENT_QUOTES, "UTF-8");
....
$mail -> Body     = "
<b>Reisezeitraum:</b> {$_POST['date1']} - {$_POST['date2']}<br>

yyyy/mm/dd instead I would like dd/mm/yyyy how can I change this?

I appreciate your help!

I have already tried to replace the PHP code with the following, but unfortunately without success, the format has not changed

$date1 = date_create('01-01-2000');
echo date_format($date1, 'd-m-Y H:i:s');
$date2 = date_create('01-01-2000');
echo date_format($date2, 'd-m-Y H:i:s');

I still got yyyy/mm/dd by mail, in addition the date from this code was displayed on an extra page: PHP

ADyson
  • 57,178
  • 14
  • 51
  • 63
XirLion
  • 1
  • 1
  • I don't understand what's stopping you from converting the output to the format you want? You've got all the tools in your question: https://3v4l.org/KEnQL – KIKO Software Mar 26 '23 at 21:53
  • Please refer to this answer on stackoverflow [How to convert date in php](https://stackoverflow.com/questions/2487921/convert-a-date-format-in-php) – Anant V Mar 27 '23 at 04:49
  • `I have already tried to replace the PHP code with the following`...well none of that has anything to do with your POST data or the values you put in the email body, so it's unsurprising that it has no effect. You're merely echoing some independent stuff. – ADyson Mar 27 '23 at 09:01
  • Demo https://3v4l.org/HQNDp shows you how to actually convert and use the posted data, as opposed to some irrelevant variables. – ADyson Mar 27 '23 at 09:07
  • @ADyson, thank you very much, your tip helped to solve my problem! Now the date is played out in the correct format! Excellent :) – XirLion Mar 27 '23 at 15:13

0 Answers0