0

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....

4 Answers 4

8
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.

Sign up to request clarification or add additional context in comments.

2 Comments

You're welcome, I am also going to update the answer for you.
God, I wish the PHP manual was this clear. Thanks for the 2 examples.
0

date function will do that for you.

Comments

0

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.

Comments

0

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() ] )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.