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.

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

Post

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 attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

General comments (10 comments)
General comments
hkotsubo‭ wrote over 3 years ago

According to MDN, the displayed format of input type=date can change according to the browser's locale. My guess is that mail clients might do something similar when interpreting HTML. Not sure if this can be changed (without some JS running on client side). Anyway, when submitted, the value is always sent in ISO 8601 format (yyyy-mm-dd, regardless of the displayed format), which can be properly handled at the backend

deleted user wrote over 3 years ago

Hello @hkotsubo, I don't understand why this ISO standard developers wanted to started from the end :) Also, sadly I almost don't have control about the backend of the email client and use it pretty much "out of box".

Monica Cellio‭ wrote over 3 years ago

Starting from the end means dates that are treated as strings sort correctly. Ever find yourself with a directory full of files named (or prefixed/suffixed) with things like "mar-5-2019" or "12-apr-2020"? Not the most convenient results when you sort by name. Whether this is the reason for the yyyy-mm-dd standard I don't know, but it's a reason I like it.

Alexei‭ wrote over 3 years ago

Besides the nice lexicographic order you get by default with YYYY-mm-dd, the timestamps are often extended with hour, minute, seconds, milliseconds. By starting with the year , adding them is done in a consistent way (see this).

hkotsubo‭ wrote over 3 years ago · edited over 3 years ago

ISO 8601 is intended to be "locale agnostic" and unambiguous, and this "biggest to smallest units" approach is IMO a good choice, with advantages already pointed by previous comments. It's an information exchange format, not a human friendly one (although it is friendly once you get used to it)

deleted user wrote over 3 years ago

I am used to (European?) assortment of dates as with smallest to biggest and also most of my customers... I also think that smallest to biggest is the correct way to go from my personal experience as a teacher (always when I studied math it helped me).

Peter Taylor‭ wrote over 3 years ago

What exactly do you mean by "I printed this HTML as output to my email box (via PHP)"? Do you actually mean that the form is submitted to a CGI script which e-mails the values to you, and the e-mail contains values in a format you didn't expect?

hkotsubo‭ wrote over 3 years ago · edited 5 months ago

Date formats are specific to locale/culture/country/etc. What makes sense to one doesn't necessarily make to another (in Japan, the "normal" order is year-month-day, in USA, month-day-year, in Brazil, day/month/year, and so on - nobody is "wrong"). But ISO 8601 is not intended to be locale oriented, because it was designed to be "neutral" in that matter (as its focus is information exchange, specially between systems), so a standardized format that removes ambiguity and doesn't depend on cultural factors was preferred.

hkotsubo‭ wrote over 3 years ago

When handling dates in a system, one should prefer to send/receive in a standard format (to make parsing easier), and only when presenting this to users, a specific localized format is chosen - BTW, that's exactly what browsers (and probably your mail client) do: internally, the input value is in ISO 8601, but the date is displayed in a different format, according to user's locale.

deleted user wrote over 3 years ago · edited over 3 years ago

@Peter Taylor, I meant that by the help of PHP, I create an HTML output from the HTML form. PHP processes my HTML form (after the client have filled in details and submitted it) and gives me / prints for me an HTML output as a new message in my local email client (Roundcube). While the client fills in dates which are in dd-mm-yyyy formats, the aforementioned output is (sadly for me) in yyyy-mm-dd format... But I want it to remain (or at least change to) dd-mm-yyyy format.