Miles
Miles

Reputation: 5736

PHP Print Date Variable Format

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

Answers (4)

simon622
simon622

Reputation: 3268

See the PHP date() function.

Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given.

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

Upvotes: 0

PTBNL
PTBNL

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

&#211;lafur Waage
&#211;lafur Waage

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

SilentGhost
SilentGhost

Reputation: 320009

date function will do that for you.

Upvotes: 0

Related Questions