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

Posted on 2005-05-10
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'
     SET @SQL = @SQL + '  AND (C.DateLost <=  ''' + CONVERT(VARCHAR(10), @DateFI, 111) + ''' AND LEN(P.IraCode) = 0) '
Question by:zimmer9
    LVL 28

    Accepted Solution

    It shouldn't make a difference, but if you really want it:

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

    Assisted Solution

    Change your date format to 120, or use a replace function.

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

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



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Suggested Solutions

    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 …
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    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.
    Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

    779 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

    17 Experts available now in Live!

    Get 1:1 Help Now