Solved

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

Posted on 2011-03-04
6
248 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
6 Comments
 
LVL 32

Expert Comment

by:ewangoya
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 32

Expert Comment

by:ewangoya
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 40

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 40

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

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.
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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