change date and time format in php [duplicate] - php

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

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)

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

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)

Convert time data into human readable time using PHP [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 2 years ago.
I have a time value in the following data format:
"2020-08-05T11:45:10.3159677Z"
How do I convert it to something human readable, like as follows, using PHP?
Wednesday, August 5, 2020, 11:45 AM
Try this:
echo date("H:i A, F jS, Y", strtotime("2020-08-05T11:45:10.3159677Z"));

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

How to Change Thu 1 Dec format to php date format [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
I am doing php parsing and getting date like Thu 1 Dec and I want to store it in database and my date column in database is of DATE type, so when I store this in database, it inserts 0000-00-00 because of improper format. How can I convert it into proper format?
To format the date properly, use something like this
$Date = Date('c', strtotime($Date))
The date has to be something strtotime can understand, but strtotime can understand a lot.

Categories