altzero
altzero

Reputation: 28

How to count remaining days in MySQL

My goal is to make a column in phpMyAdmin, which counts down the remaining days of a trial period (or something like that).

So for example when I set remainingDays to 30, I want the database to execute the query every 24 hrs

Is it possible to make something like this with only phpMyAdmin in hand, or do I have to put some code onto my website to send MySql Commands to subtract it?

Any help is greatly appreciated.

Upvotes: 0

Views: 832

Answers (2)

ReallyMadeMeThink
ReallyMadeMeThink

Reputation: 1071

A better approach would be to have a startDate column compute the remaining days during query execution with something like:

select 30-datediff(now(),startDate) from...

Upvotes: 2

Gordon Linoff
Gordon Linoff

Reputation: 1269493

Are you familiar with datediff()? Something like:

select datediff(target_date, curdate()) as days_remaining
from t;

That is, you can do this in a SQL query.

Upvotes: 2

Related Questions