Solved

PHP MYSQL TIMESTAMP

Posted on 2006-11-24
3
1,193 Views
Last Modified: 2013-12-12
Hello, I'm trying to figure out how to subtract timestamps.

I've got a TIMESTAMP in MYSQL and would like PHP to calculate the number of days it has been up until the current date.

How do I go about doing this?
0
Comment
Question by:cfans
  • 2
3 Comments
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 18009271
SELECT DATEDIFF(CURRENT_DATE(), yourTimestampField) AS daysDifference FROM theTable;
0
 

Author Comment

by:cfans
ID: 18009420
Is there an alternative to this?  The version of MySQL I am using doesn't seem to support that function.
0
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 150 total points
ID: 18009503
SELECT TO_DAYS(CURRENT_DATE()) - TO_DAYS(yourTimestampField) AS daysDifference FROM theTable;
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now