Solved

Query: How to select Time only from a datetime field?

Posted on 2004-09-21
4
452 Views
Last Modified: 2008-02-07
How to select only time from a datetime field?

I have a datetime field named SentTime.
I only want to select the Time from the field..

sample data of TimeSent:
21/09/2004 12:58:41 PM

But I only want to select 12:58:41 PM...
how to do it?
0
Comment
Question by:p931226
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
appari earned 30 total points
ID: 12119744
use convert function.

eg:
select convert(varchar,getDate(),108)

in your sql

Select convert(varchar,SentTime,108) from yourTable
0
 

Author Comment

by:p931226
ID: 12119825
Hi, appari
I follow ur method, it shown
19:00:00

Any method that will make it shown like:
07:00:00 PM ???

Thanks.

0
 
LVL 39

Expert Comment

by:appari
ID: 12119901
i think no direct way
try like this

select substring(convert(varchar,getdate(),100),13,9)
0
 

Author Comment

by:p931226
ID: 12120026
thanks, appari..
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question