SQL Syntax for MySQL

I am using the current query with a hardcoded date:

SELECT sStreetFullName
FROM `Residential_RESI`
WHERE `sListingDate` = '11/01/08'

How do I substitute the manually entered date with the current date dynamically in my sql query?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
assuming that your field sListingDate is date as data type, you HAVE to use YYYY-MM-DD as format!
if it is varchar, you made a data type choice error.

now, what date value do you want to get, actually, dynamically?
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you might find your luck in the list of the functions for date (and time):
UmeshSenior Principal Technical Support EngineerCommented:
Try this..

SELECT sStreetFullName
FROM `Residential_RESI`
WHERE `sListingDate` = STR_TO_DATE(REPLACE('11/01/08','/','-'),'%m-%d-%y');

Open in new window

The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Roger BaklundCommented:
If you do not want to change the date format you are using, you can use this query to get the current date dynamically:

SELECT sStreetFullName
FROM `Residential_RESI`
WHERE `sListingDate` = date_format(curdate(),'%m/%d/%y')

To change the date format, so that it easier to use the date, you could do this:

ALTER TABLE sStreetFullName ADD dListingDate DATE;

The above statement adds a column to the table. To populate it from your existing date column, use this:

UPDATE sStreetFullName SET dListingDate = STR_TO_DATE(sListingDate,'%m-%d-%y');

Check the results, and then you can drop the string column:

ALTER TABLE sStreetFullName DROP sListingDate;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Roger BaklundCommented:
Sorry, the update statement should be:

UPDATE sStreetFullName SET dListingDate = STR_TO_DATE(sListingDate,'%m/%d/%y');
Roger BaklundCommented:
Sorry again, your table is named Residential_RESI...!

ALTER TABLE Residential_RESI ADD dListingDate DATE;
UPDATE Residential_RESI SET dListingDate = STR_TO_DATE(sListingDate,'%m-%d-%y');
ALTER TABLE Residential_RESI DROP sListingDate;
Roger BaklundCommented:
...and the update was wrong again... (argh!)

UPDATE Residential_RESI SET dListingDate = STR_TO_DATE(sListingDate,'%m/%d/%y');
pda4meAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.