This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 8 years ago.
I have some issues with some dates coming back from a query in the DD/MM/YYYY format and I'd like to make them appear in the MM/DD/YYYY format.
I had this:
."<td>".$row['date']."</td>\n"
And wanted to use this to format the date:
."<td>".date_format($row['date'],'m/d/y')."</td>\n"
But instead it seems to break it.
Is there any way to format the data the way I want it to appear?
Try this:
$formatted_date= date('m/d/Y',$row['date']);
"<td>".$formatted_date."</td>";
Assuming your query is in PHP do this:
<?
$originalDate = $row['date'];
$newDate = date("m/d/Y", strtotime($originalDate));
echo $newDate;
?>
Related
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 4 years ago.
I am currently outputting a timestamp from my database (code below) but it's in the wrong format.
<p>{$row->last_updated}</p>
It is currently outputting 2018-10-23 13:36:40
The time is ok but the date isn't. This is what I want:
23-10-2018 13:36:40
What do I need to do with this code in order to display it like that?
You can use date()
<p><?php echo date('d-m-Y H:i:s',strtotime($row->last_updated));?></p>
You can change date format using PHP date function like this :
date('d-m-Y H:i:s', strtotime($row->last_updated))
This question already has answers here:
Change date format (in DB or output) to dd/mm/yyyy - PHP MySQL
(9 answers)
Closed 5 years ago.
So i am busy with coding a program though the date format is Y-m-d but i need it to be the european date format. thus having to be d-m-Y but i do not know how to do this since the files come directly from my database. echo $row['Datum'];if possible i'd love some help with this issue
Try date() like:
echo date('d-m-Y', strtotime($row['Datum']));
Ex:
$row['Datum'] = '2017-06-30';
echo date('d-m-Y', strtotime($row['Datum']));
// Output: 30-06-2017
Php Fiddle Link
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
I'm having a date format like this:
2010-09-21T00:00:00+03:00
how can i convert it to 'Y-m-d H:i:s' format?
I've tried following code but I don't think it's working:
$date = new DateTime('2010-09-21T20:00:00+03:00');
$status_date = $date->format('Y-m-d H:i:s');
It prints time like this: 2010-09-21 20:00:00
It prints exactly want you want ! So what's wrong ?
You can also use Carbon and to like this :
Carbon::parse('2010-09-21T00:00:00+03:00')->toDateTimeString();
UPDATE
Be careful, you said you want midnight but you wrote 8pm in your php !
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
How can I change the format of my date from 2016-10-05 to 10/05/2016 in php
$date= $row['date'];
So when the row echos out it'll all be the new format
Use DateTime to create an object (from the current format), allowing you to reformat the output.
$date = "2016-10-05";
$date = DateTime::createFromFormat('Y-d-m', $date);
echo $date->format('d/m/Y');
https://repl.it/DqvO
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 7 years ago.
I have a Date/time value as such;
2014-01-07T16:19:08Z
I wish to convert it to the format below using PHP
2015-03-21 02:12:01
I know I could use string replace twice over to remove the T and Z characters but doesn't seem right..
use strtotime() with date()
echo date('Y-m-d H:i:s',strtotime('2014-01-07T16:19:08Z'));
The date_format() function returns a date formatted according to the specified format.
$date=date_create("2014-01-07T16:19:08Z");
echo date_format($date,"Y-m-d H:i:s");
One more way is there
echo date('Y-m-d H:i:s',strtotime('2014-01-07T16:19:08Z'));
Update
The date_create() function returns a new DateTime object.
Reference
<?php
echo date('Y-m-d H:i:s',strtotime('2014-01-07T16:19:08Z'));
?>