Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-09-21
4
Medium Priority
?
485 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 120 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

916 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