1

I am using php date function to get date and time. But time information that I got is incorrect. What can I do for this problem solution? Thanks..

php code :

$d = date('Y-m-d h:i:s');
5
  • 2
    By incorrect what do you mean? it does not print? if the time is simply wrong, it might be your timezone setting! Commented Dec 10, 2011 at 14:39
  • 1
    The function works just fine. You either have h instead of H or you need to set the timezone with date_default_timezone_set. Commented Dec 10, 2011 at 14:41
  • And if nothing else works you could check if the server's system clock is actually sync'ed with yours. Commented Dec 10, 2011 at 14:44
  • No, you have not just discovered a bug in one of the most widely used functions in PHP. Clarify what exactly isn't the way you expect. Commented Dec 10, 2011 at 14:46
  • I am new on php so I had forggotten to use timezone. My problem solved. Thanks.. Commented Dec 10, 2011 at 14:55

2 Answers 2

4

Have you tried this?

$d = date('Y-m-d H:i:s');
Sign up to request clarification or add additional context in comments.

Comments

2

Try using the examples shown here: http://php.net/manual/en/function.date.php Careful that 'h' should be capital.

This should fix it but if still doesn't work, is your computers time correct?

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.