Home > Net >  How do I display Date time value as Specific Text
How do I display Date time value as Specific Text

Time:08-11

I have dates stored in the following format: 2022-08-09 02:36:18

I would like to Display this information as: Aug 9th, 2022 2:36am

I have tried: $result = $date->format('M jS, Y'); with this but not worked.

Trying this format causes my date to disappear from the page. What am I missing here?

CSS

.posttime {
    height: auto;
    width: auto;
    margin: 0px 0px 0px 0px;
    font-size: 15px;
    font-weight: normal;
    font-family: Arial Narrow Bold;
    position: absolute;
    top: 20px;
    right: 20px;
}

PHP

echo '
                    <Div >
                        <img  src="../profilepictures/'.$ProfilePicture.'">
                        <p >'.$UserName.'<p>
                        <p >'.date_format($Date,"M jS, Y h:i A").'<p>
                        <p>'.$Text.'<p>
                    </div>
                    <br>
                ';

CodePudding user response:

Simple do by this:

$date = "2022-08-09 02:36:18";
echo date('M jS,Y h:i A',strtotime($date));

CodePudding user response:

Try $result = date_format($date,"M jS, Y h:ia"). Checking date_format() function is using date_format(object, format) as the correct syntax.

Either that or youre using ' instead of ". Does this work?

Refer to this link.

CodePudding user response:

You can try with this-

<?php
 $date=date_create("2022-08-09 02:36:18");
 echo date_format($date,"M jS, Y h:i A"); // Aug 9th, 2022 02:36 AM
?>
  • Related