Format date in PHP MMddyyyyHHmmss to m-d-y [duplicate] - php

This question already has answers here:
Getting date format m-d-Y H:i:s.u from milliseconds
(18 answers)
Closed 1 year ago.
Date Format using PHP
Input date is '1568145593000', i need to convert into m-d-y format using php
Anyone knows how to convert this? Thanks =).

echo date('m-d-Y', 1568145593000 / 1000);
Divide the timestamp by 1000 to get the timestamp in seconds.
See:
PHP date https://www.php.net/manual/en/function.date.php
and for the formatting characters: https://www.php.net/manual/en/datetime.format.php (scroll down a bit)

Related

How to get a format of the given date or time in php? [duplicate]

This question already has answers here:
PHP function to get the date format?
(6 answers)
Closed 11 months ago.
How to get a format of the given date or time in php?
If I give date like this,
2022-03-08 06:45:06
It should return "Y-m-d H:i:s"
Is there any possible way to get the format from date?
i dont think there is such a function.
if you need to handle dates in different formats, reformat them in timestamp and then in the needed format
you can try something like this
$timestamp = strtotime("2022-03-08 06:45:06");
$newFormat = date('Y-m-d', $timestamp)

change date and time format in php [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
I am fetching time and date from MYSQLi using php. For time I am getting default 24 hr format and for date I am recieving format of y/m/d.
I want to get time in 12 hr format.
I want to get date in d/m/y format.
How to do it in php ?
In pure simple php, you can write as follow
Date
echo date('d/m/Y', strtotime($your_date));
Time
echo date('H:i', $your_time);
For the 12 hours, use
echo date('g:i A', $your_time);

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');

Convert datetime to Y-m-d H:i:s format [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 9 years ago.
I have a datetime field which saves the date in numerical format:
2013-11-23 21:21:31
I want to format this value into Y-m-d H:i:s so that instead of a list of numbers it reads as:
23rd November 2013
with or without the time, doesn't really matter too much.
Is this possible using date() or is that just for submitting data?
Convert the date string to a timestamp using strtotime() and feed it to date():
echo date('jS F Y', strtotime($dateStringFromDB));
For other available formatting options, refer to the documentation for date().

php - date format ISO 8601 [duplicate]

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'));

Categories