This question already has answers here:
Convert a date format in PHP [duplicate]
(18 answers)
Closed 7 years ago.
I've got an SQL server 2000 running with some data.
When I select one of my fields I get something like this:
Sep 21 2015 12:00:00:000AM
Sep 14 2015 12:00:00:000AM
..etc
I would like to convert this thing to "DD/MM/YYYY".
When I'm doing a query with Access I get this format, but not with PHP.
`your query and see time and take it into a variable then fetch that index that comes with time make three array like
`$ar=array();
$ar1=array();
$ar2=array();` after it apply `$ar1[0]=$ar2[0];
$ar1[2]=$ar[1];
$ar1[3]=$ar[0]." ".$ar2[1];
then implode like
$dt=implode("-",$ar1);
$data[$k]['time_from']=$dt;
and print $dt you find your structure.
$timestamp = '31/05/2001 12:22:56';
$timestamp = DateTime::createFromFormat('d/m/Y H:i:s', $timestamp);
echo $timestamp->format('Y-m-d H:i:s');
Related
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 3 years ago.
I am getting data in my php variable from database:
var_dump("The schedule is: ".$my_Schedule);
I am getting this output:
string(37) "Reviews created : 2019-10-19 03:47:57"
Now I want to use this data to show something like:
// My Desired Result
Oct 01, 2019
I don't want time here.
I am doing it like this:
<p><?=date('Y-m-d',$my_Schedule);?></p>
This is not working for me.
Kindly suggest what I am doing wrong.
Any idea or suggestion would be helpful.
Thank You.
Please use following code
echo date('M d,Y',strtotime('2019-10-19 03:47:57'));
You can use like this:
$date = date('M d, Y', strtotime('2019-10-19 03:47:57'));
echo $date;
// output Oct 19, 2019
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 4 years ago.
How would I change the date 18/08/2018 10:46:15 pm to Sat 25, 10:46:15 pm in PHP. I am doing the following:
```
$OldDate = "18/08/2018 10:46:15 pm";
$NewDate = $OldDate->format(D-j, Y-H:I:S);
echo $NewDate;
?>```
However, it is not showing anything, am I formatting it correctly?
Your old date is just a string. If you want to format it, you need to create a DateTime object using that string the constructor.
You're also incorrectly specifying the format
$OldDate = new DateTime("18/08/2018 10:46:15 pm");
echo $OldDate->format("L-j, h:i:s A");
http://php.net/manual/en/class.datetime.php
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
I have attribut date_input in my database
etat_input : 2016-06-06
I would convert my date on format:
since : 06 june 2016
I try with :
<?php echo $var['etat_input'];?>
but no result.
First convert date_input to timestamp:
$timestamp = strtotime($var['etat_input']);
Now feed that $timestamp to date with proper format:
date('d M Y', $timestamp);
PHP Sandbox example
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
php how to change date to this format [duplicate]
Closed 8 years ago.
I have this php script
date('dS F Y', strtotime($dateVariable))
The result is this:
01st September 2014
but I need the result as this: 01st Sep 2014
in other words, I need not the full name of the month. is that possible please?
date('dS M Y', strtotime($dateVariable))
Try as below
date('dS M Y', strtotime($dateVariable))
You can do it directly with the date function, using the 'M' mode.
http://php.net/manual/en/function.date.php
Alternatively, check out the function JDMonthName -- using mode 2 you can get the abbreviated month name.
http://php.net/manual/en/function.jdmonthname.php
Alternatively, check out the strftime function (much like printf) for formatting your date. The %b format gives the abbreviated month name.
http://php.net/manual/en/function.strftime.php
This question already has answers here:
Convert a date format in PHP [duplicate]
(18 answers)
Closed 9 years ago.
I am using MySQL and php. When I get a date from MySQL it is in the format yyyy-MM-dd. Once I get this string, how can I convert it to format of example Jan 2 2013 in php?
I tried
date("M j Y", mysql_result($recordset, $i, 'date_started'));
using http://www.php.net/manual/en/function.date.php as a reference, but I get some weird date as the output.
The PHP date() method needs a timestamp, so convert your mysql date string to a timestamp first using strtotime():
date("M j Y", strtotime(mysql_result($recordset, $i, 'date_started')));
Or better yet, format your date in your mysql query directly using DATE_FORMAT. You don't really even need PHP to do this.
Using the DateTime wrapper gives you functionality that is worth having. To convert from mysql Format, simple follow this pattern.
$mysqlDate = '2014-01-01';
$myDate = new DateTime($mysqlDate);
echo $myDate->format('M j Y');
you could use date_format in mysql like this
DATE_FORMAT(NOW(),'%b %d %y') //%b is the short name of a month