locked
Need to split colum and add to it RRS feed

  • Question

  • User709978785 posted

    I have a tbl in Access that has a name column and a YearStarted column. The YearStarted column is a month/year format like 01/1991. I need to turn all of them into this format 01/01/1991.  No matter what month and year I need to insert the 01/ part. They are not all the same month and year.

    Can anyone offer any suggestions?

    Monday, July 2, 2012 12:48 PM

Answers

  • User-1199946673 posted
    SELECT '01/' & LEFT([YearStarted], 2)  & '/'  & RIGHT([YearStarted], 4) FROM [TableName] 
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 2, 2012 6:35 PM

All replies

  • User1424224880 posted
    Use the string insert method like such?

    string myString;
    myString.Insert(2, "stuff");
    Monday, July 2, 2012 12:50 PM
  • User709978785 posted

    I was incorrect. The YearStarted column is in this format 011991. What can I do with that to insert the /01/?

    Monday, July 2, 2012 1:01 PM
  • User-1199946673 posted
    SELECT '01/' & LEFT([YearStarted], 2)  & '/'  & RIGHT([YearStarted], 4) FROM [TableName] 
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 2, 2012 6:35 PM
  • User3866881 posted

    The YearStarted column is a month/year format like 01/1991. I need to turn all of them into this format 01/01/1991. 

    Hello:)

    If you bind the field to the GridView,in fact I think you can set the formation to something like {0:MM/dd/yyyy},here's a sample if you are using TemplateField——

    <ItemTemplate>
        <%#Eval("YourBoundDataTimeField","{0:MM/dd/yyyy}")%>
    </ItemTemplate>
    Tuesday, July 3, 2012 9:47 PM
  • User-1199946673 posted

    If you bind the field to the GridView,in fact I think you can set the formation to something like {0:MM/dd/yyyy},

    Decker, it isn't a datetime column!!!!

    Wednesday, July 4, 2012 7:18 AM
  • User3866881 posted

    Decker Dong - MSFT

    If you bind the field to the GridView,in fact I think you can set the formation to something like {0:MM/dd/yyyy},

    Decker, it isn't a datetime column!!!!

    Sorry but the questioner doesn't say that clearly……And if it isn't a real Datetime column but something of a string, in fact we can still use DateTime.ParseExact method;But


     No matter what month and year I need to insert the 01/ part. They are not all the same month and year.


    Since your string of datetime doesn't include "Day" part, how can I decide which day I should add?Do you mean I have to add "01" to your DateTime of string formation so easy?

    Just like——

    <%#Eval("BoundDateTimeField","01/{0}").ToString()%>

    Wednesday, July 4, 2012 9:32 PM
  • User-1199946673 posted

    Sorry but the questioner doesn't say that clearly……

    Really???

    how can I decide which day I should add?Do you mean I have to add "01" to your DateTime

    That is exactly what he's asking:

    "The YearStarted column is a month/year format like 01/1991. I need to turn all of them into this format 01/01/1991. No matter what month and year I need to insert the 01/ part"

    Thursday, July 5, 2012 4:16 PM