Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Date format using CONVERT  (Dashes format vs. Slashes format)

Posted on 2005-05-10
2
Medium Priority
?
2,149 Views
Last Modified: 2008-03-17
I get the following result by using the CONVERT function that follows:

(C.DateLost <=  '2002/06/30'  AND P.PropertyType='FIXED INCOME' AND LEN(P.IraCode) = 0)  

Is there a way to change this date conversion to express the date as 2002-06-30 ?  (hyphenated date vs. slashed date)

If @Prop = 'ALL'
   BEGIN
     SET @SQL = @SQL + '  AND (C.DateLost <=  ''' + CONVERT(VARCHAR(10), @DateFI, 111) + ''' AND LEN(P.IraCode) = 0) '
   END
0
Comment
Question by:zimmer9
2 Comments
 
LVL 28

Accepted Solution

by:
rafrancisco earned 1000 total points
ID: 13970577
It shouldn't make a difference, but if you really want it:

If @Prop = 'ALL'
   BEGIN
     SET @SQL = @SQL + '  AND (C.DateLost <=  ''' + REPLACE(CONVERT(VARCHAR(10), @DateFI, 111), '/', '-') + ''' AND LEN(P.IraCode) = 0) '
   END
0
 
LVL 9

Assisted Solution

by:paelo
paelo earned 1000 total points
ID: 13970584
Change your date format to 120, or use a replace function.

CONVERT(VARCHAR(10), @DateFI, 120)

REPLACE(CONVERT(VARCHAR(10), @DateFI, 111),'/','-')

-Paul.

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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 extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

578 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