Is there a way I can make a query in MySQL that will give me the difference between two timestamps in seconds, or would I need to do that in PHP? And if so, how would I go about doing that?
Share
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.
You could use the
TIMEDIFF()and theTIME_TO_SEC()functions as follows:You could also use the
UNIX_TIMESTAMP()function as @Amber suggested in an other answer:If you are using the
TIMESTAMPdata type, I guess that theUNIX_TIMESTAMP()solution would be slightly faster, sinceTIMESTAMPvalues are already stored as an integer representing the number of seconds since the epoch (Source). Quoting the docs: