Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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.

yyyy/mm/dd instead expected dd/mm/yyyy format in PHP-created-HTML output

+1
−1

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" or dir="rtl" attributes-values and direction: ltr or direction: 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?

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

General comments (10 comments)

1 answer

+3
−0

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");
}
History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

General comments (2 comments)

Sign up to answer this question »