Combing two dates into on column

  • Is there a way that I can take two date variables and combine them into a single column?

    eg

    INPUT:

    PeriodStartDate = '02/01/2008'

    PeriodEndDate='02/15/2008'

    OUTPUT:

    EffectiveDate =' 02/01 - 02/15'

    Thanks,
    Art
    Database Analyst
    Tastefully Simple, Inc.

    alorenzini@tastefullysimple.com
    " Some days, it's not even worth chewing through the restraints!

  • Cast them to char first with a format you like, then chop off what you don't want:

    left(convert(char,PeriodstartDate,101),5)+' - '+left(convert(char,PeriodEndDate,101),5)

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • You want one character field, correct? Here you go:

    SELECT CONVERT(CHAR(5), GETDATE()-7, 110) + ' - ' + CONVERT(CHAR(5), GETDATE(), 110)

    Just replace the "GETDATE()" part with the dates you want to use.

    Dan

  • This works great,thanks.

    Thanks,
    Art
    Database Analyst
    Tastefully Simple, Inc.

    alorenzini@tastefullysimple.com
    " Some days, it's not even worth chewing through the restraints!

  • What are you trying to accomplish? Storing dates in any other form than a datetime column causes problems down the road.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • I need to display the dates displayed in this format but they will not used for calculations.

    Thanks,
    Art
    Database Analyst
    Tastefully Simple, Inc.

    alorenzini@tastefullysimple.com
    " Some days, it's not even worth chewing through the restraints!

  • Ah. So you are only going to use this in a SELECT to diplay the values. I had thought that you were going to create a new column to store this value.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Correct,it for a report.

    Thanks,
    Art
    Database Analyst
    Tastefully Simple, Inc.

    alorenzini@tastefullysimple.com
    " Some days, it's not even worth chewing through the restraints!

  • Hi,

    As per the database design policy you should not concatinate the fields. May be right now you dont have any requiremnts to update these values but later if there is one then its difficult to implement. So at the database level store it in two columns while diplaying it concatinate the fields.

    Thanks -- Vj

    http://dotnetvj.blogspot.com

  • Just curious, Art... haven't seen it before... what does a "Database Analyst" do? In other words, what's the job description for a "Database Analyst"?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • I think it is used as a general term Jeff. In my previous job, I was an application developer for about 6 years. I showed some savvy with working with our UNIX servers so they made me the UNIX administrator on top of my existing duties. Since our UNIX servers housed Oracle and Progress DBs, I was given responsibility over them as well. And finally, they gave me the SQL Server windows servers and changed my title to Programmer / Database Analyst. I was working in the roll of production DBA, UNIX administrator and part time programmer.

    I was hired on in my current job as a Senior DBA focusing solely on SQL Server development. The company I worked for changed their job pay grades and my title got changed to Lead Database Analyst. Our company has since been bought out and I think I will be getting yet another title change this month to match up with the new companies job description and pay grades. I guess I don't really care what they call me as long as the checks still cash and I'm getting good yearly increases.

    PS....I know this question was directed at someone else, but I thought I'd chime in 😀

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply