Reputation: 5736
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....
Upvotes: 0
Views: 13937
Reputation: 3268
See the PHP date()
function.
Returns a string formatted according to the given
format
string using the given integertimestamp
or the current time if no timestamp is given.string date ( string $format [, int $timestamp = time() ] )
Upvotes: 0
Reputation: 6130
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.
Upvotes: 0
Reputation: 70021
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.
Upvotes: 8