Skip to main content
Inspiring
June 8, 2010
Question

SQL help ?

  • June 8, 2010
  • 1 reply
  • 781 views

My table 'voucher_codes' contains a MySQL "voucher_expiry_date" field eg 2010-07-01

I need to devise a select clause that looks for an expired date ie. the date field is either today or earlier

How do I phrase that ?

Select *

From voucher_codes

Where voucher_expiry_date LTE Now()

This topic has been closed for replies.

1 reply

Inspiring
June 8, 2010

Best advice?  When asking a MySQL question, ask it on a MySQL forum!

However here you are... and here's some docs to read:

http://dev.mysql.com/doc/refman/5.0/en/non-typed-operators.html

(I am just googling this stuff you know... you could "probably" DIY).

--

Adam

Inspiring
June 8, 2010

thanks for that

it was the coldfusion bit - trying to get a variable that was today's date but in MySQL format - I'll google it

Inspiring
June 8, 2010

OK, well you wouldn't need to do the date bit in CF.  The DB is just as aware of what a date is as CF is, so there's no need/point in doing the date bit in CF then passing it to the DB, when the DB can do the whole lot by itself.  I pointed you to the correct page... that's got MySQL's date functions on it (well: in a link on the RHS), including MySQL's equivalent to CF's now() function, which - oddly enough - is called... now() (I'm not meaning sounding smug or sarcastic here... I did not know until I checked just now).

So you - perhaps inadvertantly - didn't need help with the now() bit as you already had it right.  It's just the operator bit you needed help with.

My point stands, though: asking Qs on the correct forum is a good approach (even though you got the right answer - maybe - here), because you're more likely to get better answers.  I'm working with a DBA for the first time in my professional career at present and it's driven home to me how little - as a CF developer - I really know about DBs (and I don't think I'm particularly thick when it comes to DBs/SQL).  CF bods will know enough to get by, but people focusing on the DB will know the best way to do things. Also, CF people will be splitting their DB competence across a number of platforms (SQL Server, Oracle, MySQL, etc), whereas people on a MySQL forum will be experts in MySQL.  I wasn't trying to be dismissive.  Although it probably sounded that way (eating dinner with one hand, one the phone with another, typing with my... um... magic third hand, I guess ;-)

--

Adam