How can I convert timstamp to a readable time? [duplicate] - php

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
How can I convert 2016-12-20T18:36:14.000Z to a readable date/time in PHP?
like Dec 20, 2016.

$olddate = '2016-12-20T18:36:14.000Z';
echo date('M d,Y',strtotime($olddate));

Use the DateTime::format() like this:
<?php
echo date_create('2016-12-20T18:36:14.000Z')->format('M d, Y');
output:
~$ php test.php
Dec 20, 2016l

Try this:
date('mdY') == date('mdY', strtotime($timestamp))

Following will do the trick
$t = "2016-12-20T18:36:14.000Z";
echo date('M d,Y', strtotime($t));

Related

How to remove separator in date? [duplicate]

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"]));
?>

converting string to date in php not giving exact year [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
can somebody help me with my problem? I already figure out the problem but seems i do not now how to solve it without using explode(), so the problem is that the string date for example '02-15-17' i want to convert it in date() expected result (Feb 15, 2017) using strtotime() doesn't give me a right/exact year cause of the parameter 3 which is the year it has only 2 digit in HTML5 input tag date in chrome browser, can somebody help me to solve this problem? for the vision of my code here it is.
<?php
$user_date = '02-15-17';
echo date('M d, Y', strtotime($user_date));
?>
result:
Feb 2, 1917
You could also use a DateTime with the format function:
$user_date = '02-15-17';
$dateTime =DateTime::createFromFormat('m-d-y', $user_date);
echo $dateTime->format('M d, Y');
That will give you:
Feb 15, 2017
Output php
Since all your date are over 2000's use substr function try this
$olddate = "02-15-17";
$standarddate = substr($olddate,3,2) . "." . substr($olddate,0,2) . "." . "20" . substr($olddate,6,2);
echo date("jS F, Y", strtotime($standarddate)).' - '.$standarddate;
output : 15th February, 2017 - 15.02.2017

Extract hour information from a date string [duplicate]

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

Convert string date to new format [duplicate]

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

Converting month name in given date into month number [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP date format converting
I have a date like 2012-september-09. How to convert this into 2012-09-09 using PHP?
You can try with strptime
$date = '2012-september-09';
$strp = strptime($date, '%Y-%B-%d');
$ymd = sprintf('%04d-%02d-%02d', $strp['tm_year'] + 1900, $strp['tm_mon'] + 1, $strp['tm_mday']);
$new_date = new DateTime($ymd);
echo $new_date->format('Y-m-d');
here's a Codepad
Try this
Change
<?php echo date('Y-m-d',strtotime('2012-september-09'));?>
To
<?php echo date('Y-m-d',strtotime('09-september-2012'));?>

Categories