php time convert to friendly

I have this
echo date("jS \of F Y", strtotime($displayDateTime));

Open in new window

Result is
1st of January 1970
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Loganathan NatarajanLAMP DeveloperCommented:
what format do want to have?
Loganathan NatarajanLAMP DeveloperCommented:
if you need  dd/mm/yyyy

try echo date("d/m/Y");
Loganathan NatarajanLAMP DeveloperCommented:
if you need m/d/y, try like this,

echo date("m/d/y");
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Loganathan NatarajanLAMP DeveloperCommented:
Otherwise, try with date_parse_from_format

Ray PaseurCommented:
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.
Pramod NairTehnology SpecialistCommented:
I think the example you have given has some problem


what does 04-03 stands for? That is why it is showing as 1st of January 1970
Ray PaseurCommented:
<?php // RAY_temp_glynco.php
echo "<pre>";


$ugly = '2012-04-03-17:06:52';
if (!$timestamp = strtotime($ugly)) echo "$ugly DOES NOT COMPLY WITH ISO STANDARDS";
echo PHP_EOL;

$lump = explode('-', $ugly);
= $lump[0]
. '-'
. $lump[1]
. '-'
. $lump[2]
. 'T'
. $lump[3]

if ($timestamp = strtotime($good)) echo "$good COMPLIES WITH ISO STANDARDS";
echo PHP_EOL;
echo date("jS \of F Y", $timestamp);

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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:52"; 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
   $displayDateTime = "03-04-2012 17:06:52";
   echo date("jS \of F Y", strtotime($displayDateTime));
result as 3rd of April 2012
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.