I am making a request to twitter API and I want to extract the time from date in php and store in mysql..Does anyone know how to do that?
The time and date that i get from the results is this …created_at”: “Thu, 26 Jul 2012 22:16:59 +0000”
Thank you
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Storing timestamps in database
Use
strtotime()on PHP side andFROM_UNIXTIME()on MySQL’s side.So basically your code, in short, may look like this:
The above assumes you are storing the timestamp in the column with proper type (
TIMESTAMP). To read more on differences betweenTIMESTAMP,DATEandDATETIMEsee this documentation page: MySQL Documentation: The DATE, DATETIME, and TIMESTAMP Types.Storing time as string
If you want to store the timestamp in the way that is not timezone-aware (anything else than
TIMESTAMPand not including timezone information), you will need to form the string representing your timestamp on the PHP side:Note, that
date_default_timezone_set()call is optional – if you want the time in some specific timezone, different than current. The above assumes you want timestamp in the form of “HH:MM:SS“.