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!

Showing just the Date or Time element from a DateTime Field

Status
Not open for further replies.

StevenK

Programmer
Joined
Jan 5, 2001
Messages
1,294
Location
GB
I have adopted a SQL server 7.0 database that contains fields of type 'DateTime'. Some of these fields are used solely for the storing of 'Date' entries and similarly some for 'Time' entries. Obviously with the data-type being 'DateTime' these fields have both a 'Date' and a 'Time' element.
How do I extract just the 'Date' (or the 'Time') element from these fields as required ?
I'm thinking its possible (maybe through CAST'ing and such) but can't seem to see it straight off.
Can anyone suggest how I can do this ?
I can do this through a delphi front-end (by reading the 'DateTime' as a String and taking the appropriate substring of this) but ideally want to obtain the information directly through the database query.
Thanks in advance.
Steve
 
Have a look at DATEPART and the CONVERT functions in SQL Server Books Online.

They will do the job for you.

Rick.
 
Thanks for this information - it has provided me with the solution that I've been looking for.
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top