php - date format ISO 8601 [duplicate] - php

This question already has answers here:
How do I convert an ISO8601 date to another format in PHP?
(2 answers)
Closed 9 years ago.
I have encountered this date format:
2013-03-12T09:16:12.1550656+01:00
from what I have found in net this is ISO 8601 (am I correct?).
How can I convert this this date format using php?
I can generate it easily using date('c'), but I need convert this type of date:
20130422122037 - (YYYYMMDDHHMMSS)

Try this:
$date = new DateTime('20130422122037');
var_dump($date->format('c'));

Related

Change Date format from 2018-09-27T18:30:00.000Z to 2018-09-27 13:17:14 [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 4 years ago.
When I select a date using angular md-datepicker I receive date in 2018-09-27T18:30:00.000Z this format but in my database i have dates in 2018-09-27 13:17:14 this format, how can I convert dates in PHP to search in the database please help me.
First create DateTime object then change to format whatever you want.
$dateTime = new DateTime('2018-09-27T18:30:00.000Z');
$databaseFormat = $dateTime->format('Y-m-d H:i:s');

I want to save different date format tha saved in yii2 datepicker [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Format date dd/mm/yyyy to yyyy-mm-dd PHP [duplicate]
(7 answers)
PHP convert date format dd/mm/yyyy => yyyy-mm-dd [duplicate]
(5 answers)
How to convert MM/DD/YYYY to YYYY-MM-DD?
(8 answers)
Yii2 View DateTime Format (d-m-Y H:i:s) But When Save/update in DB Change format to Y-m-d H:i:s
(5 answers)
Closed 5 years ago.
I am using yii2 datepicker in my project.
I want to show selected date as dd/mm/YYYY but want to save date in model as YYYY-mm-dd.
How can I do so?
You can format datepicker in Controller,and then render the view.
Controller:
$model->birth_date=Yii::$app->formatter->asDate($model->birth_date, "dd/mm/yyyy");
Then Store like this:
$model->birth_date=Yii::$app->formatter->asDate($model->birth_date, "yyyy-mm-dd");

Change type of date in html table - php mysql [duplicate]

This question already has answers here:
Convert from MySQL datetime to another format with PHP
(18 answers)
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
I need some help with converting the date to dd/mm/YYYY.
I have this code to display my date in a html table from a mysql database
echo "<td>".$zeile['datumFahrt']."</td>";
Can I convert it in this line so the format will be dd/mm/YYYY instead of YYYY/mm/dd?
Sure you can, first you need to convert it to timestamp and then format it:
date("d/m/Y", strtotime($zeile['datumFahrt']))

PHP Convert Date/Time format from 'd/m/Y H:i:s' to 'H:i:s'? [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 7 years ago.
I have a timestamp column in my database with dates and times formatted like '24/06/2015 14:30', but I need to convert it to just '14:30'. I've tried everything please help.
Very easy to use, just pass in argument and format: http://php.net/manual/en/class.datetime.php

what format is this datetime string: 2001-12-17T09:30:47-05:00 [duplicate]

This question already has answers here:
Why does DateTime add a T separator to the timestamp?
(4 answers)
Closed 8 years ago.
I need to generate a MessageTime for a xml based api. In the example request file, they are using the following:
<MessageTime>2001-12-17T09:30:47-05:00</MessageTime>
What is the format of this datetime string? I want to generate it using date() method or DateTime class.
This is what I tried so far: I am in the UK, so i am using the offset 00:00
var_dump(date('Y-m-d\TH:i:s').'-00:00')
// Output: 2014-05-26T20:11:45-00:00
Is this correct?
ISO 8601 date (added in PHP 5):
date('c');
Or using a constant:
date(DateTime::ISO8601);
You can also utilize O for the "difference to Greenwich time (GMT) in hours":
date('Y-m-d\TH:i:sO');

Categories