Php format date dd/mm/yyyy

I have sầu the following date: 2010-04-19 18:31:27. I would like to lớn convert this date khổng lồ the dd/mm/yyyy format.


Bạn đang xem: Php format date dd/mm/yyyy

You can use a regular expression or some manual string fiddling, but I think I prefer:

date("d/m/Y", strtotime($str));
I find on a lot of our servers (operating on Australian time) I need khổng lồ use: date("d/m/o", strtotime($str)); -> i.e 'o' for the year. – niggles Apr trăng tròn "10 at 1:57
Hi there! I have sầu already tried your solution but does not seems lớn work. Like I asked on my post, I just need the date in the dd/mm/yyyy format without the time component. Thanks for the help, Best regards! – Rui Gonçalves Aquảng bá 20 "10 at 9:09
Which part doesn't work? strtotime("2010-04-19 18:31:27"); returns the seconds since the epoch, 1271716287 (for my TZ). date() takes a format string & an epoch int; the format string tells it what khổng lồ return, & "d/m/Y" is days as a zero-padded int, months as a zero-padded int, and year as four digits. Since no time parameters are included in the format string (e.g. "d/m/Y h:i:s"), they won't be returned – Michael Mrozek Apr 20 "10 at 14:03
Hi there! I was commiting an error with the application of the suggested solution. It worked just fine! To all others, thanks for the responses. Thanks again for the response! Best regards – Rui Gonçalves Aquảng cáo 21 "10 at 21:52
And current date date("d/m/Y"); – Junior Mayhé Sep 19 "15 at 23:19

If your date is in the format of a string use the explode function

array explode ( string $delimiter , string $string <, int $limit > ) //In the case of your code $length = strrpos($oldDate," "); $newDate = explode( "-" , substr($oldDate,$length)); $output = $newDate<2>."/".$newDate<1>."/".$newDate<0>;

Hope the above works now


This is far more complex of a solution than what is needed. – Mitch Dempsey Apr 19 "10 at 22:40

But useful for other possible cases. – James P.. Aug 3 "11 at 13:02


There is also the DateTime object if you want to go that way: http://www.php.net/manual/en/datetime.construct.php


Try this:

$old_date = Date_create("2010-04-19 18:31:27"); $new_date = Date_format($old_date, "d/m/Y");
$source = "your varible name"; $date = new DateTime($source); $_REQUEST<"date"> = $date->format("d-m-Y"); emang lại $_REQUEST<"date">;
Please don't leave sầu signatures under your post. – Glorfindel Jul 4 "17 at 8:27

The question says convert khổng lồ "dd/mm/yyyy". This solution seems to lớn give sầu the wrong format. – Pang Jul 5 "17 at 1:32


Thanks for contributing an answer khổng lồ Staông chồng Overflow!

Please be sure khổng lồ answer the question. Provide details & share your research!

But avoid

Asking for help, clarification, or responding to lớn other answers.Making statements based on opinion; baông chồng them up with references or personal experience.

To learn more, see our tips on writing great answers.


Post Your Answer Disthẻ

By clicking “Post Your Answer”, you agree to lớn our terms of service, privacy policy & cookie policy


Not the answer you're looking for? Browse other questions tagged php date format or ask your own question.


Why does the Bible put the evening before the morning at the kết thúc of each day that God worked in Genesis chapter one?


Xem thêm: Mọi Sự Là Vì Em - Pin On Vpop Music Videos

Is there a broader term for instruments, lượt thích the gong, whose volume briefly increases after being sounded instead of immediately decaying?
Absence of evidence is not evidence of absence: What does Bayesian probability have khổng lồ say about it?
Which governors can flip the Senate as of March 2021? more hot questions
Staông chồng Overflow Questions Jobs Developer Jobs Directory Salary Calculator Help mobile
Products Teams Talent Advertising Enterprise
Company About Press Work Here Legal Privacy Policy Terms of Service Liên hệ Us
Staông xã Exchange Network Technology Life / Arts Culture / Recreation Science Other
Stachồng Overflow Server Fault Super User Web Applications Ask Ubuntu Webmasters Game Development
TeX - LaTeX Software Engineering Unix & Linux Ask Different (Apple) WordPress Development Geographic Information Systems Electrical Engineering
Android Enthusiasts Information Security Database Administrators Drupal Answers SharePoint User Experience Mathematica
Salesforce ExpressionEngine® Answers Staông xã Overflow em Português Blender Network Engineering Cryptography Code nhận xét
Magento Software Recommendations Signal Processing Emacs Raspberry Pi Stachồng Overflow на русском Code Golf
Staông chồng Overflow en español Ethereum Data Science Arduino Bitcoin Software Quality Assurance & Testing Sound Design
Windows Phone more (28)
Photography Science Fiction & Fantasy Graphic Design Movies & TV Music: Practice & Theory Worldbuilding Video Production
Seasoned Advice (cooking) Home Improvement Personal Finance & Money Academia Law Physical Fitness Gardening & Landscaping
Parenting more (10)
English Language & Usage Skeptics Mi Yodeya (Judaism) Travel Christianity English Language Learners Japanese Language
Chinese Language French Language German Language Biblical Hermeneutics History Spanish Language Islam
Русский язык Russian Language Arqade (gaming) Bicycles Role-playing Games Anime & Manga Puzzling
Motor Vehicle Maintenance & Repair Board & Card Games Bricks Homebrewing Martial Arts The Great Outdoors Poker
Chess Sports more (16)
MathOverflow Mathematics Cross Validated (stats) Theoretical Computer Science Physics Chemistry Biology
Computer Science Philosophy Linguistics Psychology & Neuroscience Computational Science more (10)

Blog Facebook Twitter LinkedIn Instagram

site kiến thiết / hình ảnh sản phẩm © 2021 Stachồng Exchange Inc; user contributions licensed under cc by-sa. rev 2021.3.5.38726