Solved

CONVERT DATETIME AND CAST DATEPART

Posted on 2006-11-01
6
1,401 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

910 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

22 Experts available now in Live!

Get 1:1 Help Now