Solved

Hour date in 1:00 AM format fro ms sql server 2005

Posted on 2011-03-04
6
262 Views
Last Modified: 2012-05-11
How do I conver this:
DECLARE @CURR_DATE smalldatetime
 SET  @CURR_DATE = ISNULL(@CURR_DATE, getDATE())

to this:
1:00 AM
0
Comment
Question by:GlobaLevel
[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
6 Comments
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35038720

try using convert
select CONVERT(varchar,  @CURR_DATE, 108)
0
 
LVL 3

Expert Comment

by:AndrewSkoraro
ID: 35038732
CONVERT(@CURR_DATE , GETDATE() , 108)
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 35038774
is this right?

DECLARE @CURR_DATE smalldatetime
 SET  @CURR_DATE = ISNULL(@CURR_DATE, getDATE())

DECLARE @DAILY_CURR_DATE nvarchar(max)
SET @DAILY_CURR_DATE = select CONVERT(varchar,  @CURR_DATE, 108)
0
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!

 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35038806

Remove the select

DECLARE @CURR_DATE smalldatetime
 SET  @CURR_DATE = ISNULL(@CURR_DATE, getDATE())

DECLARE @DAILY_CURR_DATE nvarchar(max)
SET @DAILY_CURR_DATE = CONVERT(varchar,  @CURR_DATE, 108)
0
 
LVL 41

Accepted Solution

by:
Sharath earned 500 total points
ID: 35039327
try this.
DECLARE @CURR_DATE smalldatetime
 SET  @CURR_DATE = ISNULL(@CURR_DATE, getDATE())
 SELECT CASE WHEN DATEPART(HOUR,@CURR_DATE) BETWEEN 0 AND 11 THEN CAST(DATEPART(HOUR,@CURR_DATE) AS VARCHAR(2)) + ' AM'
            ELSE CAST(DATEPART(HOUR,@CURR_DATE)-12 AS VARCHAR(2)) + ' PM'
        END AS time_AMPM
-- 11 AM

Open in new window

0
 
LVL 41

Expert Comment

by:Sharath
ID: 35039348
You can try this if you are working in SQL Server 2008.
DECLARE @CURR_DATE smalldatetime
 SET  @CURR_DATE = ISNULL(@CURR_DATE, getDATE())
 select CONVERT(varchar,CONVERT(time,@CURR_DATE),100)
 -- 11:46AM
 

Open in new window

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

Suggested Solutions

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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