Home > Microsoft Access Help > Date to String in SQL statement

Date to String in SQL statement



Hi,



I have to be able to execute an sql statement which would look something like this.



SELECT *

FROM Table1

WHERE start_date LIKE '*01*'



The problem is this does not work since start_date is from the type date.



How can I convert the start_date field to a string in order to execute the where clause?

    
Guest


Hi,

This depends on what you want to do...I can't promise you these will all work since this is untested, but it's along these ideas to check out....



If you're not worried about the year:



-- e.g. For January

SELECT *

FROM MyTable

WHERE MONTH(DateField) = 1



Or, if you do need to limit to a specific year:

a)

-- e.g. for January 2003

SELECT *

FROM MyTable

WHERE MONTH(DateField) = 1 AND YEAR(DateField) = 2003



b)

-- e.g. for January 2003

SELECT *

FROM MyTable

WHERE DateDiff(m, DateField, '2003-01-01') = 0



also check out some other date functions that may help you, google around for date functions

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved