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

Extract date from datetime field

Status
Not open for further replies.

creedprg

MIS
Aug 31, 2005
18
PH
Hello Guys

is there any way to extract date from DATETTIME field in SQL sever? In visual foxpro i just issue a command using TTOD(Datetime()) but in MS SQL this TTOD function is not supported, May i know some equivalent command for this function....


Thank you in advance.
 
Check CAST and CONVERT() function in BOL.

Borislav Borissov
VFP9 SP2, SQL Server
 
Liek Borislav said,

CAST(column as date)
or
CONVERT(date, column)

CAST is ANSI sql standard, CONVERT is T-SQL dialect code. So I'd go for CAST in cases it works and only take CONVERT for the cases CAST is too simple, in this case, CAST works ok.

By the way, you could also CAST(column as time) to get the time portion only, since that is a new* type, too. And to put date and time together use date+CAST(time as datetime)

Bye, Olaf.


*new: it has bneen some years now.
 
use
select convert(varchar(12), getdate(), 101)

just replace getdate() with any datetime value
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top