Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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

Posted on 2004-09-21
Medium Priority
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?
Question by:p931226
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 39

Accepted Solution

appari earned 120 total points
ID: 12119744
use convert function.

select convert(varchar,getDate(),108)

in your sql

Select convert(varchar,SentTime,108) from yourTable

Author Comment

ID: 12119825
Hi, appari
I follow ur method, it shown

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


LVL 39

Expert Comment

ID: 12119901
i think no direct way
try like this

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

Author Comment

ID: 12120026
thanks, appari..

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

688 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