Solved

CONVERT DATETIME AND CAST DATEPART

Posted on 2006-11-01
6
1,409 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]
ID: 17853003
I am not sure to fully understand what you are requesting?...
0
 
LVL 6

Expert Comment

by:davbouchard
ID: 17853303
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
ID: 17853311
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
ID: 17853345
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
ID: 18281040
PAQed with points refunded (50)

Computer101
EE Admin
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

770 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