Solved

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

Posted on 2004-09-21
4
443 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now