Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date portion of datetime 1

Status
Not open for further replies.

password99

Technical User
Jul 19, 2002
122
0
0
US
how to get just the date portion of datetime value?

so if values in DB are:
12/31/2004 11:25:39
12/31/2004 11:21:19
12/31/2004 00:00:00

then I want either 12/31/2004 00:00:00 or 12/31/2004 returned
 
Here you go

Code:
SELECT CONVERT (DATETIME, CONVERT (VARCHAR, getDATE(), 101))

-Kris

 
Just type this in your select statement:

LEFT(Tbl_Name, 10)

This returns 10 chars starting from the left. Be careful on how the date is being stored. Using 10 is assuming that you have leading zeros in your date field.. 01/02/2004.
good luck

Mike Cormier
May God bless everything you do...
 
Thanks

is it possible to convert it into date as the converted value will be used in SELECT statement/View and it requires it to be a date/datetime. what I am interested in is date without the time portion .i.e.
12/31/2004 00:00:00 or 12/31/2004
 
Select field1,
CONVERT (DATETIME, CONVERT (VARCHAR(10), getDATE(), 101)),
field3
from SomeTable

just put it into your select statement.

~Brian
 
mike, dates in sql server are not stored as mm/dd/yyy strings with or without leading zeroes, dates are stored as whole integers, representing the number of days since january 1 1753

rudy
SQL Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top