6

I have javascript that turns dates in my view to a time string using getTime(). That then is stored as a value for an option in my select form. Once it is passed to php, how do I turn that into a php date?

I have done:

echo date("m/d/Y", '1345618799000');

1345618799000 = Tue Aug 21 2012
0

2 Answers 2

9

You use PHP's date() function:

date("Format here (see documentation)", round($_POST["time_field"]/1000));

Updated, thanks Yoshi.

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

5 Comments

that's what i did but its off by a lot
@chris What did you use for format? Also, if you did try something first (which is something nearly everyone here requires for a question) add it to the question.
@chris That's expectable as js' getTime includes milliseconds, while date does not expect them. Try dividing the timestamp by 1000 first.
echo date("m/d/Y", '134630999900');
+1 ;) though the obvious error checking on $_POST["time_field"] should not be forgotten in production code.
0

You may use PHP's strtotime() to change any string into a Unix timestamp; strtotime()

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.