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().
Related
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)
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);
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.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
convert php date to mysql format
I have a date field which lets users type in their birthday in m/d/Y format (for example 06/01/1982) but just in case I also made my validation accept month and day values without any leading 0 (6/1/1982).
How can I convert these dates to Y-m-d for use in MySQL?
Other valid dates are 6/01/1982 and 06/1/1982.
You could use date() and strtotime() together like such:
$date = date('Y-m-d', strtotime('06/01/1982'));
That will give you
1982-06-01
I would validate all input using strtotime (which will handle all major date formats).
On the insert, cast it to the proper format using the inverse: strftime:
$userValidatedDate = strtotime($_GET['date']);
//...
$sqlDate = strftime('%Y-%m-%d',$userValidatedDate);
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Numerical Date To Text Date PHP
I'm trying to find a way to convert a date to a more "user-friendly" format.
For example, from 2011-01-05 to Jan 5th, 2011.
I'm sure it's something simple, I just can't seem to find it anywhere. Any ideas?
For the th add the English ordinal Suffix for the day of the month
date("M jS, Y", strtotime("2011-01-05"));
Try this:
date("M j, Y", strtotime("2011-01-05"));
You could use the DateTime class, and call the format function. Then just set up the format using the standard date() format string to output a textual data format.