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?
pda4meAsked:
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?
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you might find your luck in the list of the functions for date (and time):
dev.mysql.com/doc/mysql/en/date-and-time-functions.html
0
UmeshMySQL Principle 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

0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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;
0

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');
0
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;
0
Roger BaklundCommented:
...and the update was wrong again... (argh!)

UPDATE Residential_RESI SET dListingDate = STR_TO_DATE(sListingDate,'%m/%d/%y');
0
pda4meAuthor Commented:
Thanks!
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.