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
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:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
I'm writing some code a script, which has short dates like
14/12/17
30/11/17
20/11/17
I need to convert these to long date format so i used PHP date function and strtotime as below
echo date('d-m-Y',strtotime('14/12/17'));
But it always getting 01-01-1970 as output, but it should be 14-12-2017
anyone know how to convert this to a long date format please.
PS. Other question answers suggest change the date input format, but I cannot change date input since it's getting from another site
This is from the link I posted and OP says is not correct.
Originally posted by ceiroa.
Convert one date format into another in PHP
$myDateTime = DateTime::createFromFormat('d/m/y','14/12/17');
$newDateString = $myDateTime->format('d-m-Y');
Echo $newDateString;
https://3v4l.org/2AcAd
Use preg_replace to flip the day and month on the incoming dates, then use date as you want.
$orig = ['14/12/17', '30/11/17', '20/11/17'];
foreach ($orig as $s) {
echo date('d-m-Y', strtotime(preg_replace('#(\d+)\/(\d+)\/(\d+)#', '$2/$1/$3', $s)))."\n";
}
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;
?>
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Covert time format in php
I am getting a start_time field value from mysql data base as 2012-08-14 21:30:00
and i want to convert it in php format like 2012-08-14T09:30 is there any method to do
this in php ?
use strtotime()
$date = strtotime('2012-08-14 21:30:00');
echo date('Y-m-d\Th:i',$date);
see this example.for the required date & time format:
$date=date("Y-m-d H:i:s");//get the current date
$d=strtotime($date);//convert in strtotime
echo $final_date=date("Y-m-d\Th:i:s",$d);//in the first argument of date ,put the format whatever you want,but be sure to convert it in strtotime first.
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 2 years ago.
I am tring to make the google news sitemap by php script from mysql.(all the date save as timestamp in +08:00)
But how to converting date to YYYY-MM-DD hh:mm:ssTZD?
For example 1338048000 => 2012-05-26T09:00:00+08:00
echo date("Y-m-d T h:i:s",'1338048000').'+08:00';//2012-05-26 PDT 09:00:00+08:00
Not the result what I need. And how to? Thanks.
How about this?
echo date("c",'1338048000');
I'd say:
gmdate('Y-m-d\TH:i:s\Z', '1338048000');
The T means something, and needs to be escaped. Or, since PHP5, the ISO8601 date format is natively supported with the c character.
Additionally, using gmdate instead of date removes the need to worry about timezones.
echo date("c", "1338048000").'+08:00';