[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Get Current Time

Posted on 2006-05-23
6
Medium Priority
?
4,665 Views
Last Modified: 2010-10-05
I am adding the current date to a column when adding a record using
Getdate()

I want to store the current time in a seperate column. How do i get just the time.
0
Comment
Question by:Kevin Robinson
  • 2
  • 2
5 Comments
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 16745443
Use CONVERT() with or without substring, depending on the specific time format you need.  Please specify details: hh:mm [24 hr] | hh:mmAM | ...
0
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 2000 total points
ID: 16745461
For example:

SELECT CONVERT(CHAR(8), GETDATE(), 108)  --hh:mm:ss, 24 hr format
SELECT CONVERT(CHAR(12), GETDATE(), 114) --hh:mm:ss.sss, 24 hr format
SELECT RIGHT(CONVERT(VARCHAR(30), GETDATE(), 100), 7) --hh:mmAM
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 16745554
if your using getdate() then you already have the time stored as well...

can you post the code you've got currently

in what situation are you trying to retrieve/maintain the information?
0
 
LVL 34

Expert Comment

by:Brian Crowe
ID: 16745691
Why would you store them separately?
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 16752964
>Why would you store them separately?

it could make communication with systems that support independant Date and Time datatypes easier ...

(e.g. DB2/UDB)

;-)

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
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.
Suggested Courses

873 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