Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Getting only the date part from a datetime field

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-08-23 : 09:55:30
Prakash writes "Hi,
Probably it might be a cake walk for you specialists-how do i truncate only the date part from a datetime date field. Suppose i have a table date_table with a column date_column. I am storing date values in this table like 2002-08-12 10:46:11.000
but when i make a select statement i just need the date part like 2002-08-12 , exclduing the time part.
Thanks in Advance

Prakash"

dsdeming

479 Posts

Posted - 2002-08-23 : 10:08:40
You can use CONVERT:

SELECT CONVERT( datetime, CONVERT( char( 8 ), GETDATE(), 112 ))

The CONVERT to char( 8 ) will strip out the time. When you CONVERT it back, the time is set to 0.

If you don't want to display the time at all:

SELECT CONVERT( char( 8 ), GETDATE(), 112 )

Of course, this way all you have is a string.


Go to Top of Page
   

- Advertisement -