Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on yyyy/mm/dd instead expected dd/mm/yyyy format in PHP-created-HTML output
Parent
yyyy/mm/dd instead expected dd/mm/yyyy format in PHP-created-HTML output
I have an HTML-PHP-CSS contact form with a date field:
<input type="date" name="date" id="cf_input_date"></input>
- The default value in this field is the W3C built-in default:
dd/mm/yyyy
- The date-picking pattern in this field is the W3C built-in default
dd/mm/yyyy
My problem
Everything was allegedly fine until I printed this HTML as output to my email box (via PHP).
In my email box, the output pattern for picked dates is the exact opposite of the pattern I already use in the form:
yyyy/mm/dd
Things I have tried to solve it
-
dir="ltr"
ordir="rtl"
attributes-values anddirection: ltr
ordirection: rtl
properties-values don't help in flipping the output - Various CSS tricks all ended in failure
- Sadly I can't use JavaScript comfortably in this case because the email output appears in a third party email client which doesn't easily allow JavaScript manipulation of the DOM
My question
How to ensure that my HTML-PHP output is in dd/mm/yyyy
pattern (as default for the input field itself) instead the "flipped" yyyy/mm/dd
?
Post
The date is sent in the form submission in ISO 8601 format (year-month-day). You can reformat it in the form handler as follows:
$input_date = $_REQUEST['cf_input_date'];
if ($input_date)
{
$input_date = DateTime::createFromFormat("Y-m-d", $input_date)->format("d/m/Y");
}
1 comment thread