00 Votes

MySQL: Days since Date

Question by Compi | 2016-02-23 at 13:24

I would like to determine how old a contribution or comment in my database is.

That means, that I meet some function to calculate the number of passed days since the date or timestamp of the corresponding article.

How is it possible to get the number of days since a specified date in MySQL?

ReplyPositiveNegative
0Best Answer0 Votes

You can just use the MySQL function DATEDIFF(). This function returns the difference between two timestamps measured in days.

Here is an example of how to use it:

SELECT id, txt, dat, DATEDIFF(CURDATE(), dat) FROM tab;

In this example, our table "tab" is consisting of the columns "id", "txt" and "dat". The date of the contribution is stored in the column "dat".

We want to read out the content of all columns as well as the passed days since that date in "dat". For this, we are using the function DATEDIFF() with passing the current date with CURDATE() and the date of the column "dat" in order to get the time difference.
2016-02-23 at 16:02

ReplyPositive Negative
Reply

Related Topics

PHP: Current Date and Time

Tutorial | 0 Comments

PHP: Determine Week Number

Tutorial | 0 Comments

Change Date of File

Tutorial | 0 Comments

VirtualBox: Change Date and Time

Tutorial | 10 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.