Convert a date format in PHP

0 votes
I am trying to convert a date from yyyy-mm-dd to dd-mm-yyyy but however I don't know how the date function requires a timestamp, and I can't get a timestamp from this string.

How is this possible?
Feb 17, 2022 in Others by Rahul
• 9,670 points
1,819 views

1 answer to this question.

0 votes
Use strtotime() and date():
$originalDate = "2010-03-21"; $newDate = date("d-m-Y", strtotime($originalDate));

Note that this was a quick solution to the original question. For more extensive conversions, you should really be using the DateTime class to parse and format. 

answered Feb 17, 2022 by Aditya
• 7,660 points

Related Questions In Others

0 votes
1 answer
0 votes
1 answer

Convert Excel's "41014" date to actual date in PHP or JavaScript

PHPExcel Date handling code: public static function ExcelToPHP($dateValue ...READ MORE

answered Oct 24, 2022 in Others by narikkadan
• 51,240 points
338 views
0 votes
1 answer

Convert text date/time to a real date time in excel

For a date conversion: =DATEVALUE(TEXT(A1,"MM/DD/YYYY")) For a time conversion: =TIMEVALUE(TEXT(A1,"HH:MM:SS")) For ...READ MORE

answered Dec 19, 2022 in Others by narikkadan
• 51,240 points
56 views
0 votes
0 answers

Date time convert in Replace activity in word document scope

we have input in excel  New date/Header 31/12/2020 31/12/2019 We  want ...READ MORE

Jun 22, 2020 in Others by Sapna
• 120 points

recategorized Jun 22, 2020 by Gitika 195 views
0 votes
1 answer

Format JavaScript date as yyyy-mm-dd

You could try using the following lines ...READ MORE

answered Feb 23, 2022 in Java-Script by Aditya
• 7,660 points
3,307 views
0 votes
0 answers

How do I use PHP to get the current year?

I want to put a copyright notice ...READ MORE

Jun 9, 2022 in PHP by Kichu
• 19,040 points
82 views
0 votes
0 answers

Format die(); Message in PHP

Is there a way to style the ...READ MORE

Jun 10, 2022 in PHP by narikkadan
• 51,240 points
67 views
0 votes
0 answers

Convert one date format into another in PHP

How can I convert one date format ...READ MORE

Jun 20, 2022 in PHP by Kithuzzz
• 27,740 points
63 views
0 votes
1 answer

How do I get the current date and time in PHP?

The time would go by your server ...READ MORE

answered Feb 16, 2022 in Others by Aditya
• 7,660 points
208 views
0 votes
1 answer

How to fix "Headers already sent" error in PHP

The functions that send and modify the ...READ MORE

answered Feb 17, 2022 in Others by Aditya
• 7,660 points
2,732 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP