Solved

Datetime

Posted on 2009-07-11
6
172 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
  • 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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 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

20 Experts available now in Live!

Get 1:1 Help Now