This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Format mysql datetime with php
How to convert the following:
2010-12-07 12:00:00
into:
December, 7th, 2010
echo date("F, jS, Y", strtotime("2010-12-07 12:00:00"));
http://php.net/manual/en/function.date.php
Check out the date function.
$myDate = strtotime('2010-12-07 12:00:00');
$formattedDate = date('F, jS, Y', $myDate)
Use date_format
http://www.php.net/manual/en/function.date-format.php
$date = date_create('2010-12-07 12:00:00');
echo date_format($date, 'F, jS, Y');
echo date('F, jS, Y',strtotime('2010-12-07 12:00:00'));
$d = strtotime('2010-12-07 12:00:00');
echo date('F, jS, Y', $d);
Related
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 8 years ago.
Can anyone please help?
I have searched many website (including stackoverflow) but can't find my exact answer.
It may be so easy, but I need to know.
2014-11-21 18:49:55
I need to convert it to
6:49 PM, 21th November, 2014
Can anyone help me please?
Thanks in advance for helping.
This should work for you:
$date = "2014-11-21 18:49:55";
echo date('g:i A, dS F Y', strtotime($date));
Output:
6:49 PM, 21st November 2014
Try this-
$date = "2014-11-21 18:49:55";
echo date('g:i A, jS F, Y', strtotime($date));
Output -
6:49 PM, 21st November, 2014
$originalDate = "2014-11-21 18:49:55";
$newDate1 = date("g:i A,", strtotime($originalDate));
$newDate2 = date("d", strtotime($originalDate));
$newDate3 = date("F, Y", strtotime($originalDate));
echo $newDate1.' '.$newDate2.'th '.$newDate3;
<?php
$providedTime = '2014-11-21 18:49:55';
$newTime = strtotime($providedTime);
echo date('g:i A, dS F Y', $newTime);
?>
[Working example][1]
We can use PHP's date() function to get the provided date in required format.
the date() function has various parameters and we can use nice use of them.
Hope it works for you.
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 8 years ago.
I receive a date from an array in the below format:
2014-10-22 07:24:57 EDT
I want to convert this to echo only the month and day like this: Oct 22
My code below works fine when I'm changing from the 15-Feb-2009 format.
<?php
$date = DateTime::createFromFormat('D-M-Y', '15-Feb-2009');
$nice_date = $date->format('M j');
echo $nice_date;
?>
Here's what I have that doesn't work. Probably not even close.
$array_date = '2014-10-22 07:24:57 EDT';
$date = DateTime::createFromFormat('YY-MM-DD HH:II:SS EDT', $array_date);
$nice_date = $date->format('M j');
echo $nice_date;
I'm at a loss right now. Any ideas?
If you want to explicitly provide the format, you must provide the correct format.
$array_date = '2014-10-22 07:24:57 EDT';
$date = DateTime::createFromFormat('Y-m-d H:i:s e', $array_date);
$nice_date = $date->format('M j');
echo $nice_date;
$str = "2014-10-22 07:24:57 EDT";
echo date("M d", strtotime($str)); // Oct 22
Try following ( i used date and strtotime ) :
$originalDate = "2014-10-22 07:24:57 EDT";
$newDate = date("M j", strtotime($originalDate));
echo $newDate;
$array_date = '2014-10-22 07:24:57 EDT';
$date = DateTime::createFromFormat('YY-MM-DD HH:II:SS EDT', $array_date);
$nice_date = date('M d',$date);
echo $nice_date;
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 8 years ago.
I get the date in the variable date as
$date = "<?php echo $projects->dob;?>" ; //where let dob=2013-01-12
I want to convert this into Jan 2013 format. How to convert in php?
do:
echo date('M Y', strtotime($your_date));
see: Date Formats
$dob = '2013-01-12';
echo date('M Y', strtotime($dob));
$date = date('M Y', strtotime($projects->dob));
Example:
https://ideone.com/tdJl8O
$timestamp = strtotime("2013-01-12");
$formatted = date("M Y", $timestamp);
Demo: http://codepad.org/Lw2eEq6Q
echo $date = date("M Y",strtotime($projects->dob)) ;
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP convert one date into another date format
This is PHP
I have this result:
2011-09-20 13:00:00
I want to convert it into this format:
September 20 2011 1:00 pm
Do you know how to do that?
Anyhelp would be greatly appreciated.
Thanks!
try this:
$old_date = '2011-09-20 13:00:00';
$old_date_timestamp = strtotime($old_date);
$new_date = date('F j Y g:i a', $old_date_timestamp);
If that result comes from an object of type DateTime you can use the format function:
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');
and here all the formats you can have.. change it according to your needs.
You can get the UNIX-timestamp of a time string with strtotime() and you can get a differently designed time string with strftime()
For more information you can read the documentation here : http://php.net/manual/en/function.date.php
But also is simple. Lets see how
$d = "2011-09-20 13:00:00";
$d = strtotime($d);
$d = date("F m Y g:i a", $d);
echo $d;
Take a look at these PHP functions:
http://nl.php.net/manual/en/function.date.php
and
http://nl.php.net/strtotime
To do something like this:
date('F d Y G:i',strtotime("2011-09-20 13:00:00")); // your required format
You can use this format
$date= date("F j Y g:i a");
if you have date in any variable then
$date= date("F j Y g:i a",strtotime($your_variable));
echo $date
echo date("F d Y g:i a",strtotime("2011-09-20 13:00:00 "));
echo date('F d Y g:i a', strtotime('2011-09-20 13:00:00'));
check the date format
This question already has answers here:
Convert from MySQL datetime to another format with PHP
(18 answers)
Closed 2 years ago.
I have a date time in a variable. My format is 08/04/2010 22:15:00. I want to display this like 10.15 PM. How to do this in PHP?
You need to convert it to a UNIX timestamp (using strtotime) and then back into the format you require using the date function.
For example:
$currentDateTime = '08/04/2010 22:15:00';
$newDateTime = date('h:i A', strtotime($currentDateTime));
$dateString = '08/04/2010 22:15:00';
$dateObject = new DateTime($dateString);
echo $dateObject->format('h:i A');
Use strtotime() to make the date a UNIX timestamp.
For output, check out the various options of date().
$timestamp = strtotime("08/04/2010 22:15:00");
date("h.i A", $timestamp);
<?php
$dateTime = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
echo $dateTime->format("d/m/y H:i A");
?>
You can use this to display the date like this
22/06/15 10:46 AM
Like this:
$date = '08/04/2010 22:15:00';
echo date('h:i A', strtotime($date));
Result:
10:15 PM
More Info:
date
strtotime
for flexibility with different formats, use:
$dt = DateTime::createFromFormat('m/d/Y H:i:s', '08/04/2010 22:15:00');
echo $dt->format('g:i A')
Check the php manual for additional format options.
PHP Code:
date_default_timezone_set('Asia/Kolkata');
$currentDateTime=date('m/d/Y H:i:s');
$newDateTime = date('h:i A', strtotime($currentDateTime));
echo $newDateTime;
Output: 05:03 PM
$currentDateTime = $row['date'];
echo $newDateTime = date('l jS \of F Y h:i:s A', strtotime($currentDateTime));
Perfect answer for AM/PM live time solution
<?php echo date('h:i A', time())?>
Just simply right A
{{ date('h:i A', strtotime($varname->created_at))}}
For (PHP >= 5.2.0):
You can use DateTime class. However you might need to change your date format. Didn't try yours.
The following date format will work for sure: YYYY-MM-DD HH-MM-SS
$date = new DateTime("2010-04-08 22:15:00");
echo $date->format("g"). '.' .$date->format("i"). ' ' .$date->format("A");
//output
//10.15 PM
However, in my opinion, using . as a separator for 10.15 is not recommended because your users might be confused either this is a decimal number or time format. The most common way is to use 10:15 PM
It is quite easy. Assuming you have a field(dateposted) with the type "timestamp" in your database table already queried and you want to display it, have it formated and also have the AM/PM, all you need do is shown below.
<?php
echo date("F j, Y h:m:s A" ,strtotime($row_rshearing['dateposted']));
?>
Note: Your OUTPUT should look some what like this depending on the date posted
May 21, 2014 03:05:27 PM