MySQL Forums
Forum List  »  PHP

Re: Passing variable from form to php for SQL select
Posted by: Barry Galbraith
Date: February 15, 2016 02:45PM

?can I do "todays date" minus statusdt as age ?

You can do that with DATEDIFF()
mysql> SELECT DATEDIFF(NOW(),'2016-01-01');
+------------------------------+
| DATEDIFF(NOW(),'2016-01-01') |
+------------------------------+
|                           46 |
+------------------------------+
1 row in set (0.01 sec)

Another way you could get the same thing is with DATE_SUB()
If you want the date 3 days before today you find it like this.
mysql> select date_sub(now(), interval 3 day);
+---------------------------------+
| date_sub(now(), interval 3 day) |
+---------------------------------+
| 2016-02-13 07:34:30             |
+---------------------------------+
1 row in set (0.17 sec)

So your form could submit "How many days old is your status" and just submit a number (e.g. 3). and your query filters on
... WHERE statusdt > date_sub(now(), interval 3 day);

Good luck,
Barry.

Options: ReplyQuote


Subject
Written By
Posted
Re: Passing variable from form to php for SQL select
February 15, 2016 02:45PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.