 |
| SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 7th, 2005, 11:24 PM
|
|
Registered User
|
|
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
DateTime
I'm new to SQL Server 2000 and have a question about DateTime. I'm more comfortable with Access and how it handles dates. I use a # for dates there. Also I never had the actual time in the field either. Now I have a table in SQL Server with date and time. I try to run a query with just date but it doesn't work. How can I convert this field to just date, or what function can I use in my query to just look at the date and ignore the time? Thanks.
|
|

December 8th, 2005, 12:45 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
All date type fields in SQL have the time in them. You can simply not save the time, or convert the datetime to a char to remove the time from being displayed. Most other databases have a date only field type of some sort but MS-SQL does not.
|
|

December 8th, 2005, 12:51 PM
|
|
Authorized User
|
|
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Play around with this
declare @date datetime
select @date = convert(varchar,getdate(),110) --or select @date = '20051208'
select @date,dateadd(d,1,@date) -- just so that you can see what the date looks like
select * from table
where datefield >= @date
and datefield < dateadd(d,1,@date)
âI sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" -- http://sqlservercode.blogspot.com/
|
|

December 9th, 2005, 04:45 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2005
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
SELECT CONVERT(varchar(10), field1, 103) FROM Table1
SELECT CONVERT(varchar(10), getDate(), 103) FROM Table1
change the style(103) as you want.
If you have any datetime parameters, convert them also
SELECT * FROM table1 WHERE CONVERT(varchar(10), field1, 103) = CONVERT(varchar(10), @Parameter1, 103)
|
|

December 9th, 2005, 06:45 AM
|
|
Authorized User
|
|
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Nalla, If you do a convert on a datetime field you will get a table scan instead of an index seek/scan and that will degrade performance
âI sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" -- http://sqlservercode.blogspot.com/
|
|

December 13th, 2005, 11:31 PM
|
|
Friend of Wrox
|
|
Join Date: Dec 2005
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
SqlMenace,
Suppose my table name is Table 1 and the field name is Field1 and the values in my field is stored in this format,
2005-03-25 10:17:36.390
I want to select all the records from Table1 where Field1 = '25/03/2005'
so what I'm doing is,
@parameter1 = '25/03/2005'
SELECT * FROM Table1 WHERE CONVERT(varchar(10), Field1, 103) = CONVERT(varchar(10), @Parameter1, 103)
Please tell me how to do this without the CONVERT function or any methods better than this.
|
|

December 14th, 2005, 06:51 AM
|
|
Authorized User
|
|
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Nalla, you can do it like this
declare @parameter1 datetime
select @parameter1= '20050325'
select @parameter1,dateadd(d,1,@parameter1) -- just so that you can see what the date looks like
select * from table
where Field1 >= @parameter1
and Field1 < dateadd(d,1,@parameter1)
âI sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" -- http://sqlservercode.blogspot.com/
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| datetime |
scandalous |
SQL Server 2005 |
3 |
December 19th, 2007 10:33 AM |
| datetime |
MathLearner |
Beginning VB 6 |
0 |
November 15th, 2007 07:12 AM |
| DateTime |
pzmrcd |
C# |
3 |
July 26th, 2007 06:35 AM |
| UTC DateTime to Local DateTime |
r_ganesh76 |
SQL Server 2000 |
1 |
April 4th, 2005 08:21 AM |
| DateTime |
DARSIN |
General .NET |
1 |
December 1st, 2004 06:24 AM |
|
 |