glynco
asked on
php time convert to friendly
I have this
Result is
1st of January 1970
$displayDateTime="2012-04-03-17:06:52";
echo date("jS \of F Y", strtotime($displayDateTime));
Result is
1st of January 1970
what format do want to have?
if you need dd/mm/yyyy
try echo date("d/m/Y");
try echo date("d/m/Y");
if you need m/d/y, try like this,
<?php
echo date("m/d/y");
?>
<?php
echo date("m/d/y");
?>
Otherwise, try with date_parse_from_format
ref. http://de3.php.net/manual/en/function.date-parse-from-format.php
ref. http://de3.php.net/manual/en/function.date-parse-from-format.php
The issue here is that you have got "almost" an ISO-8601 DATETIME string with this: 2012-04-03-17:06:52 If it said 2012-04-03T17:06:52 your code would work. So my question would be, "Where did that string come from?" If your code is generating it, change the code to generate something in the date('c') format. If you are getting it from an external source, ask the data provider to correct the data so that it complies with ISO-8601 standards. If the data provider is unable to do that you can try replacing the rightmost hyphen with the letter 'T' and you should be OK.
I think the example you have given has some problem
$displayDateTime="2012-04- 03-17:06:5 2";
what does 04-03 stands for? That is why it is showing as 1st of January 1970
$displayDateTime="2012-04-
what does 04-03 stands for? That is why it is showing as 1st of January 1970
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
As Ray has commented
1. There has to be a required default time zone declaration for php version above 5.1
2. $displayDateTime="2012-04- 03-17:06:5 2"; is being evaluated to 0 resulting in
1st of January 1970 as date.
3. Problem is with the $displayDateTime which receives the value of the string supposed to be
converted into datetime.
4. $displayDateTime = "03-04-2012 17:06:52" should result in correct evalutation of datetime;
5.echo date("jS \of F Y", strtotime($displayDateTime ));
This following simple code has resulted in
<?php
date_default_timezone_set( 'America/C hicago');
$displayDateTime = "03-04-2012 17:06:52";
echo date("jS \of F Y", strtotime($displayDateTime ));
?>
result as 3rd of April 2012
1. There has to be a required default time zone declaration for php version above 5.1
2. $displayDateTime="2012-04-
1st of January 1970 as date.
3. Problem is with the $displayDateTime which receives the value of the string supposed to be
converted into datetime.
4. $displayDateTime = "03-04-2012 17:06:52" should result in correct evalutation of datetime;
5.echo date("jS \of F Y", strtotime($displayDateTime
This following simple code has resulted in
<?php
date_default_timezone_set(
$displayDateTime = "03-04-2012 17:06:52";
echo date("jS \of F Y", strtotime($displayDateTime
?>
result as 3rd of April 2012