Link to home
Start Free TrialLog in
Avatar of pda4me
pda4me

asked on

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?
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

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?
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
Try this..


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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, the update statement should be:

UPDATE sStreetFullName SET dListingDate = STR_TO_DATE(sListingDate,'%m/%d/%y');
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;
...and the update was wrong again... (argh!)

UPDATE Residential_RESI SET dListingDate = STR_TO_DATE(sListingDate,'%m/%d/%y');
Avatar of pda4me
pda4me

ASKER

Thanks!