Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CONVERT DATETIME AND CAST DATEPART

Posted on 2006-11-01
6
Medium Priority
?
1,441 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
[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 143

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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 …
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
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.

636 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