[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1446
  • Last Modified:

CONVERT DATETIME AND CAST DATEPART

+ ' 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
llputney
Asked:
llputney
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I am not sure to fully understand what you are requesting?...
0
 
davbouchardCommented:
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
 
David ToddSenior DBACommented:
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
 
llputneyAuthor Commented:
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
 
Computer101Commented:
PAQed with points refunded (50)

Computer101
EE Admin
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now