tags:

views:

103

answers:

6

Hi All,

I am trying to check if a regulation's date reminder is today and regulation's date end not yet passed then I do not want it to display. the problem is the query that I made isn't work in mysql. Can anyone help me to revise my query?

Here is my query:

$query="select * from t_regulation where dt_reminder >= '$today' and dt_ended ='$today'"

please help me...

+2  A: 

This is assuming that your dt_reminder columns type is DATETIME, and not some sort of timestap.

SELECT * FROM t_regulation WHERE DATE(dt_reminder) >= CURDATE() AND DATE(dt_ended) = CURDATE()
duckyflip
A: 

You can do many funky things with date functions;

Mysql date/time functions

simon622
A: 

@ Stefan Thyberg : yes the query is correct but only work on PostgreSQL. If I execute the query on MySQL it will return an empty result.Please help me..

@duckyflip: I have try your query but still return an empty result. I use type data DATE for columns dt_reminder and dt_ended.Please help me

A: 

Very frequently I run into the problem that my date variable is a string that is not properly formatted for the default date time stamp in Mysql.

Remember it should be 'yyyy-mm-dd' for this comparison.

Also, for since the 'date ended' has not yet passed, shouldn't it be:

$query="select * from t_regulation where dt_reminder >= '$today' and (dt_ended > '$today' or dt_ended is null)"

aronchick
A: 

here is my table stucture, values, and my code

table structure is:

t_master_reg

|field | type data |

id_reg |VARCHAR

no_reg |VARCHAR

reg_subject | VARCHAR

dt_reg_stated | DATE

dt_reg_end | DATE

dt_reg_reminder | DATE

values ('1','regulation no 546','regulation subject','2009-05-05','2009-07-31','2009-06-31')

$query="select * from t_regulation where dt_reminder >= '$today' and dt_ended >='$today'"

I dont why its still not work on my sql

is your variable $today correct? maybe the its pulling the wrong date off the server.
kylex
A: 

@kylex : I have check the $today variable and it'w works.. I don't know why this query can't be excute on mysql

Chandradyani