tags:

views:

489

answers:

4

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

I'm patching up some PHP code (I'm not a PHP'er) and I have this variable $orderDate. How do I print this variable so that its 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 be getting today's date....

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

Depends on what $orderDate contains.

Look into date() since it has there plenty of examples and is pretty simple to use.

UPDATE:

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

Also check out to see if this works for you.

Ólafur Waage
i guess $orderDate was a string, so that second one worked
Miles
You're welcome, I am also going to update the answer for you.
Ólafur Waage
A: 

date function will do that for you.

SilentGhost
A: 

See the php date function

simon622
A: 

If $orderDate is an integer time stamp, you probably want strftime. Specifically, I think the call you want would be:

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

However, I recommend reviewing the web page to make sure I've interpreted what you want correctly.

PTBNL