Thread: query involving dates
Hi, I need to query some records based on fields of type date, however, it seems that every dbms' date format is different. In access, you use #1/1/99#. In oracle, you need to use Jan-1-99. Is there a standard format for dealing with dates? I have a set of records with a column called "myDate". I'm looking for a query that tells the DB to return all records with "myDate" within 7 days from today. How can I do that? Thank you very much. Please reply to twong@cmpmail.com. -Al
Dates must be enclosed in single quotes in SQL Server. Use date functions to build queries like the one you describe. Here is an example that works in the pubs sample database: select ord_date from sales where ord_date between '9/13/94' and dateadd(dd, 7, '9/13/94') -- Bob Pfeiff MCDBA, MCSD, MCSE, MCT, SQL Server MVP Practice Leader, Data Management CIBER, Washington, DC
And.... use the "convert" function, for example: convert(char(10),datevar,105) , u will have dd-mm-yyyy ... or use the format u want to.. Bob Pfeiff <bobp@spectrumtech.com> escribi� en el mensaje de noticias O7IFj#$9#GA.270@cppssbbsa04... > Dates must be enclosed in single quotes in SQL Server. Use date functions > to build queries like the one you describe. Here is an example that works > in the pubs sample database: > > select > ord_date > from > sales > where > ord_date between '9/13/94' and dateadd(dd, 7, '9/13/94') > > -- > Bob Pfeiff > MCDBA, MCSD, MCSE, MCT, SQL Server MVP > Practice Leader, Data Management > CIBER, Washington, DC > >