[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2011-03-04
6
Medium Priority
?
275 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

650 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