0

I want to check my expiry date with current time using NOW() function

Process: I am adding reminder date time with jQuery UI Date time picker and its giving me time stamp like this 2015-07-9 14:36 it does not have any seconds but my created_at contain complete Unix time stamp.

But using the below command doesn't give me any result. MySQL date time set with PC date and time.

MySql Code:

SELECT * FROM `tbl_web_contact_signups` WHERE `expiry` = NOW()

Database:

+----+-----------------+---------------------+
| ID |      expiry     |     created_at      |
+----+-----------------+---------------------+
|  1 | 2015-07-9 14:36 | 2015-07-01 11:22:24 |
+----+-----------------+---------------------+
|  2 | 2015-07-9 14:38 | 2015-07-01 11:22:24 |
+----+-----------------+---------------------+
|  3 | 2015-07-9 14:40 | 2015-07-01 11:22:24 |
+----+-----------------+---------------------+
|  4 | 2015-07-9 14:50 | 2015-07-01 11:22:24 |
+----+-----------------+---------------------+

Expiry column type varchar

PS: i am creating reminders and want to check how many reminders i have today or this time.

2
  • where is your expiration column? Jul 9, 2015 at 11:06
  • Question edited, column name changed
    – hy_sultani
    Jul 9, 2015 at 11:10

2 Answers 2

1

now() means current datetime, do you really have entry for current datetime, please check..

For check remonders of today use this query:

SELECT * FROM `tbl_web_contact_signups` WHERE date(`expiry`) = CURDATE();

For check reminders of today and current hour use this query:

SELECT * FROM `tbl_web_contact_signups` WHERE date(`expiry`) = CURDATE() and hour(`expiry`) = hour(now());

For check reminders of today and current hour and current minute use this query:

SELECT * FROM `tbl_web_contact_signups` WHERE date(`expiry`) = CURDATE() and hour(`expiry`) = hour(now()) and Minute(`expiry`)=minute(now());
7
  • now() isnt a mysql function which returns the current date and time ?
    – hy_sultani
    Jul 9, 2015 at 11:14
  • yes it is, but your query compares the data in table.. means the table must have some rows with current date and time.. otherwise how the mysql returns data ? you are comparing expiry in mysql table with current date / time Jul 9, 2015 at 11:16
  • exactly i don need seconds i need date, hr and minutes please write a query
    – hy_sultani
    Jul 9, 2015 at 11:28
  • is there any query which check first only today all reminders and then which nearly to current time show as asc or desc wise?
    – hy_sultani
    Jul 9, 2015 at 11:36
  • 1
    SELECT * FROM tbl_web_contact_signups order by expiry desc. Jul 9, 2015 at 11:42
0

Try this

 SELECT * FROM tbl_web_contact_signups WHERE  expiry = DATE_FORMAT(NOW(), '%d-%m-%Y %H:%m') ;

You must have record in expiry column with that particular time(minute) of query firing.

or just check records for today with

SELECT * FROM tbl_web_contact_signups WHERE  DATE(expiry) = CURDATE();
1
  • @hy_sultani try my first query
    – Hytool
    Jul 9, 2015 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.