PHP Print Date Print Format

So this should be a very simple question, but I can't seem to find a simple answer anywhere.

I am fixing some PHP code (I am not PHP'er) and I have this $ orderDate variable. How can I print this variable so that it's just M / d / yy h: mm tt?

Update: So I looked around and saw what $ orderDate is. Here's the code:

global $orderDate;
$orderDate = strftime('%c');
print("Order Date: ".date("M/d/Y h:M", $orderdate)."<br />");

      

so I get this for output:

Dec / 31/1969 06: Dec

and should get the date today ....

0


a source to share


4 answers


echo date("m/d/Y h:m", $orderDate);
echo date("m/d/Y h:m", strtotime($orderDate)); // or this

      

Depends on what $ orderDate contains.

Have a look at date () as it has a lot of examples and is pretty easy to use.



UPDATE:

$orderDate = date("M/d/Y h:M");
print("Order Date: ".orderDate ."<br />");

      

Also check if this works for you.

+7


a source


date

the function
will do it for you.



0


a source


See PHP function date()

.

Returns a string formatted according to the specified string format

using the specified integer timestamp

or the current time if no timestamp is specified.

string date ( string $format [, int $timestamp = time() ] )

      

0


a source


If $ orderDate is an integer timestamp, you probably want strftime . Specifically, I think you want:

strftime("%D %l:%M %p", $orderDate)

      

However, I recommend reviewing the webpage to make sure I understand correctly what you want.

0


a source







All Articles