Solved

Datetime

Posted on 2009-07-11
6
174 Views
Last Modified: 2012-05-07
Hello,
I'm new to SQL.
Here's my question,
I need to get the hour and minutes to show like hm, example (832 or 1125 or ...),
I used this :

SELECT DATEPART(hour,My Field)
SELECT DATEPART(minute,My Field)  

it gives me the info, but I can't seem able to combine both.

Thanks for any help.
0
Comment
Question by:wassimqa
[X]
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
  • 3
  • 3
6 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 24830849
SELECT cast(REPLACE(CONVERT(varchar(5),getdate(), 108),':','') AS INT)
0
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 500 total points
ID: 24830871
SELECT  CAST( DATEPART(hour,My Field) as varchar ) +
               CAST( DATEPART(minute,My Field)  as varchar )
0
 

Author Comment

by:wassimqa
ID: 24830880
I get a syntax error when using
SELECT cast(REPLACE(CONVERT(varchar(5),MY Field 108),':','') AS INT)

My field looks like: May 29 2008  8:22AM
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 500 total points
ID: 24830915
did you miss the comma

SELECT cast(REPLACE(CONVERT(varchar(5),[MY Field] ,108),':','') AS INT)
0
 

Author Comment

by:wassimqa
ID: 24831003
Ooops,
yes, I missed the comma,
Beginners mistake,
Thanks again.
0
 

Author Closing Comment

by:wassimqa
ID: 31602434
excellent work
0

Featured Post

Technology Partners: 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

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

730 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