Solved

CONVERT DATETIME AND CAST DATEPART

Posted on 2006-11-01
6
1,393 Views
Last Modified: 2012-05-05
+ ' is scheduled for ' + CONVERT(VARCHAR(20), @strdate, 102)
-- How can I just have text date output from this above?

+ ' from ' + CAST(DATEPART(hh,@strstarttime) as varchar(20)) + ':' + CAST(DATEPART(mi,@strstarttime) as varchar(20)) + ' to ' + @strendtime + '.'
-- How can I just display that time instead of a whole timestamp?
0
Comment
Question by:llputney
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
I am not sure to fully understand what you are requesting?...
0
 
LVL 6

Expert Comment

by:davbouchard
Comment Utility
I think this is what you mean??

+ ' is scheduled for ' + substring(CONVERT(VARCHAR(20), @strdate, 102),1,10)

+ ' from ' + substring(CAST(DATEPART(hh,@strstarttime) as varchar(20)),12, + ':' + CAST(DATEPART(mi,@strstarttime) as varchar(20)) + ' to ' + substring(convert(varchar(20),@strendtime,102),12,8) + '.'
0
 
LVL 35

Expert Comment

by:David Todd
Comment Utility
Hi,

> + ' is scheduled for ' + CONVERT(VARCHAR(20), @strdate, 102)
> -- How can I just have text date output from this above?

try
select CONVERT(VARCHAR(20), getdate(), 102)

select CONVERT(VARCHAR(10), getdate(), 102)

Both of these return the same string - just varying lengths.

> + ' from ' + CAST(DATEPART(hh,@strstarttime) as varchar(20)) + ':' + CAST(DATEPART(mi,@strstarttime) as varchar(20)) + ' > to ' + @strendtime + '.'
> -- How can I just display that time instead of a whole timestamp?

try
select convert( varchar( 20 ), getdate(), 114 )

You should look up the cast and convert entry in BOL. CAST and CONVERT (Transact-SQL)

There is a table listing the standard date time formats.

Regards
  David
0
 

Author Comment

by:llputney
Comment Utility
Please remove this question.  I found the answers:

+ ' is scheduled for ' + CONVERT(VARCHAR(20), @strdate, 102)
-- How can I just have text date output from this above?

CONVERT(CHAR(12),@strdate, 107) -- Output is May 11, 2006

+ ' from ' + CAST(DATEPART(hh,@strstarttime) as varchar(20)) + ':' + CAST(DATEPART(mi,@strstarttime) as varchar(20)) + ' to ' + @strendtime + '.'
-- How can I just display that time instead of a whole timestamp?

SUBSTRING(CONVERT(VARCHAR(20),@strendtime, 100), 13, 7)  -- Output is 2:57PM
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
Comment Utility
PAQed with points refunded (50)

Computer101
EE Admin
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

762 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

13 Experts available now in Live!

Get 1:1 Help Now