This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 3 years ago.
how to remove the separator from the date input I have below
$date=$_POST["input"];
$new = date_format($date,"Y M D");
Try this one
<?php
$date=$_POST["input"];
// prints the current time in date format
echo date("Y M D", strtotime($date))."\n";
?>
Use date_create() to change datatype from string to date
$date=date_create($_POST["input"];);
echo date_format($date,"Y M D");
Use strtotime function convert date string into unix timestamp. Then convert into required format.
<?php
echo date("Y M D", strtotime($_POST["input"]));
?>
Related
This question already has answers here:
Convert a date format in PHP [duplicate]
(18 answers)
Closed 2 years ago.
In my database I have 10-01-2021 (d/m/Y)
I want to display this on the website as (d F Y) "10 January 2021. However it shows as 1 October 2021
How do I tell the code that the day and the month are not in US order of month/day but actually as day/month?
I have tried using $projectCreated = DateTime::createFromFormat('d/M/Y', $projectCreated); but this doesn't echo anything.
$projectCreated = date_create($projectCreated);
$projectCreated = date_format($projectCreated,"d F Y");
You should echo formatted output instead the static class function.
$date = DateTime::createFromFormat('d-m-Y', '10-01-2021');
echo $date->format('d F Y');
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
how to re-format datetime string in php?
(9 answers)
Closed 6 years ago.
I have some strings that will be different dates and times. Each one will be different and I'm looking to format them to my liking.
For Example:
2016-04-15 14:20:00
I would like to be able to take this string and use PHP's Date function to format it to my liking.
For Example:
04/15 2:20pm
So would I take the string and convert it to a timestamp first? If so how do I go about doing that?
You can return a new DateTime object formatted according to the specified format by using this function. Then you can format it as you like.
<?php
$testDate = '15-Feb-2009 11:00:34';
$date = DateTime::createFromFormat('j-M-Y H:i:s', $testDate);
echo $date->format('Y-m-d');
?>
try this ..
<?php
$time = strtotime('2016-04-15 14:20:00');
echo date('m/d g:ia', $time);
?>
Second Way
<?php
$format = 'Y-m-d H:i:s';
$date = DateTime::createFromFormat($format, '2016-04-15 14:20:00');
echo $date->format('m/d g:ia');
?>
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 7 years ago.
Is it possible extract hour value from a date string like below
20151211091805 +0000
expected output-
09:18:05 (this should also be string)
Try this:
$t = "20151211091805";
echo date('H:i:s',strtotime($t));
Use PHP's date function.
echo date("H:i:s", strtotime("20151211091805"));
Another way using DateTime class.
$dateTime = new DateTime("20151211091805");
echo $dateTime->format('H:i:s');
Try this..
<?php
$timestamp = 20151211091805;
$date = new DateTime("$ts");
echo date_format($date, 'H:i:s');
?>
This question already has answers here:
Convert date from yyyy-mm-dd to dd month_name year [duplicate]
(2 answers)
Closed 8 years ago.
I have trouble in converting this date. What I want is to convert the date formated in yyyy-mm-dd into Month day year. How can I achieve this?
below is my code.
$news = mysql_query("SELECT * FROM tblupcomingevents WHERE date >= CURRENT_DATE() LIMIT 5") or die(mysql_error());
while($row = mysql_fetch_array($news))
{?>
<?php echo $row ["date"] ?>
<?php echo $row ["place"] ?>
<?php
}
?>
Use the PHP date function to reformat it:
echo date('F j, Y',strtotime($row['date'])); // January 30, 2015, for example.
See date for many more formatting options.
Primary objective is to convert your date string (in the format of 'yyyy-mm-dd') into timestamp. Timestamp makes it easier / possible for php to convert it into one of many formats that you may desire.
For instance, you want 2015-01-30 to be listed as January 30, 2015, all you need to do is:
<?php
$timestamp = strtotime("2015-01-30");
$formattedDate = date('F d, Y', $timestamp);
echo $formattedDate;
?>
You can, however, choose other formats for your presentation from:
http://php.net/manual/en/function.date.php
Hope it helps!
You can use strtotime()
$date=date('m-d-Y',strtotime($row["date"]));
Output would look like this:
01-01-2000
You can refer here for more date format and change the value inside the code I have given.
In MySQL, you can use date_format():
select date_format(datecol, '%M %d %Y)
The complete documentation for the function is here. It provides a lot of flexibility in the output string format for a date.
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 8 years ago.
How to convert a string, for instance
$datestring = '28.08.14 10.42';
To a new format like date("YmdHis.u")
Thank you
Use date function. There is no such format as what you have required but the what I think you want to achieve is this.
DEMO
<?php
$datestring = '28.08.14 10.42';
$date = date("Y-m-d H:i:s:u", strtotime($datestring));
echo $date; //outputs 2014-08-28 10:42:00:000000
?>
Try this
$datestring = '28.08.14 10.42';
echo date("YmdHis.u",strtotime($datestring));