Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!

I have a problem in my PHP or MySQL. It seems to be not returning the current Date and Time.

When I would run date() like 2015-28-01 1:47:00 [This is the time now], it would save in the database 2015-01-28 06:47:30??

Can someone help me to solve this?

Thank you so much and God bless. :)
Posted
Comments
Praveen Kumar Upadhyay 28-Jan-15 1:42am    
You can use date() with format. Search in google date format in php, you will get many links explaining this.
Michelle Anne Rigor 28-Jan-15 1:46am    
I have already tired that one. But still returns the wrong date. I have set the Timezone. Thankfully it worked when I added the timezone. But is there a way where I will not hard-code the timezone?
Sinisa Hajnal 28-Jan-15 2:28am    
Did you check server time? Set a breakpoint and find out is it correct in your code BEFORE saving - that is, at which point do you get wrong time. Then work backwards to find the source of the problem.

1 solution

If you want to set it permanently, open the php.ini, and add or modify this directive:
date.timezone=Asia/Singapore

restart Apache, then it will be fine.
I am using Singapore timezone as an example.
 
Share this answer
 
Comments
Michelle Anne Rigor 28-Jan-15 3:01am    
Thank you for this! Finally solve the problem. :D
Peter Leow 28-Jan-15 4:17am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900