Solved

Datetime

Posted on 2009-07-11
6
169 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

23 Experts available now in Live!

Get 1:1 Help Now