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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve only some part of datetime field...? 1

Status
Not open for further replies.

Fursten

Programmer
Joined
Dec 27, 2000
Messages
403
Location
PT
I have one field of type datetime, and I would like to retrieve - with transact SQL only the date part (day, month and year). Is it possible?

Thank you
 
Select convert(char(10), datecol, 103) As DateOnly From tbl

Style #103 returns date in dd/mm/yyyy format.

Other styles are
101 - mm/dd/yyyy
107 - mmm dd yyyy (increase size from char(10) to char(11))
112 - mmddyyyy (decrease size)

See SQL BOL Convert and Cast topic for more info. Terry
------------------------------------
Experience is the hardest kind of teacher. It gives you the test first, and the lesson afterward.
 
declare @CurentDate varchar(15)
select @CurentDate = DATENAME(day, getdate()) + DATENAME(month, getdate()) + DATENAME(year, getdate())

with this code you can read the element of the current date (day, month, year).

You could also use the DATEPART function.

Try to adapt it to your needs,

Hopr this helps,s-) Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
I dunno if this is valid -- but to do this in vb i use the left function:

Dim date as str

date= now() 'gets clock time and date

date = left(date, 10) ' just retrieve the dd/mm/yyyy

:o)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top