Convert char to date and subtract from today's date

Posted on 2007-10-14
Last Modified: 2010-05-18
Given the following table:
ID      PERIOD      DATA1
A      20070901      25
B      20060501      77
C      20071001      35
D      20070901      24
E      20071001      12
F      20070930      84
How can I convert PERIOD to its date format, and determine how many days it is from today's date?

Desired results would be similar to:
ID      DAYS      DATA1
A      43      25
B      531      77
C      13      35
D      43      24
E      13      12
F      14      84
Question by:TECHADVICE
    1 Comment
    LVL 42

    Accepted Solution

    Select ID, DateDiff(day,Convert(DateTime,Period,112), GetDate()) Days, Data1 from...

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    This is my first ever Article on EE or elsewhere; therefore, please bear with me if I have some discrepancies in my writing. I read many articles and questions related to "how to pass values to SSIS packages at run-time?"  Hence, this common ques…
    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
    Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now