Excel Date to String conversion

前端 未结 9 616
野趣味
野趣味 2020-11-28 21:17

In a cell in Excel sheet I have a Date value like:

01/01/2010 14:30:00

I want to convert that Date to Text and also want the Text to look e

相关标签:
9条回答
  • 2020-11-28 21:51

    Couldnt get the TEXT() formula to work

    Easiest solution was to copy paste into Notepad and back into Excel with the column set to Text before pasting back

    Or you can do the same with a formula like this

    =DAY(A2)&"/"&MONTH(A2)&"/"&YEAR(A2)& " "&HOUR(B2)&":"&MINUTE(B2)&":"&SECOND(B2)

    0 讨论(0)
  • 2020-11-28 21:56

    The selected answer did not work for me as Excel was still not converting the text to date. Here is my solution.

    Say that in the first column, A, you have data of the type 2016/03/25 21:20:00 but is stored as text. Then in column B write =DATEVALUE(A1) and in column C write =TIMEVALUE(A1).

    Then in column D do =B1+C1 to add the numerical formats of the date and time.

    Finally, copy the values from D into column E by right clicking in column E and select Paste Special -> Paste as Values.

    Highlight the numerical values in column E and change the data type to date - I prefer using a custom date of the form YYYY-MM-DD HH:MM:SS.

    0 讨论(0)
  • 2020-11-28 22:01

    Here is a VBA approach:

    Sub change()
        toText Sheets(1).Range("A1:F20")
    End Sub
    
    Sub toText(target As Range)
    Dim cell As Range
        For Each cell In target
            cell.Value = cell.Text
            cell.NumberFormat = "@"
        Next cell
    End Sub
    

    If you are looking for a solution without programming, the Question should be moved to SuperUser.

    0 讨论(0)
  • 2020-11-28 22:02

    In Excel 2010, marg's answer only worked for some of the data I had in my spreadsheet (it was imported). The following solution worked on all data.

    Sub change()
        toText Selection
    End Sub
    
    Sub toText(target As range)
    Dim cell As range
    Dim txt As String
        For Each cell In target
            txt = cell.text
            cell.NumberFormat = "@"
            cell.Value2 = txt
        Next cell
    End Sub
    
    0 讨论(0)
  • 2020-11-28 22:06

    Here's another option. Use Excel's built in 'Text to Columns' wizard. It's found under the Data tab in Excel 2007.

    If you have one column selected, the defaults for file type and delimiters should work, then it prompts you to change the data format of the column. Choosing text forces it to text format, to make sure that it's not stored as a date.

    0 讨论(0)
  • 2020-11-28 22:06

    If you are not using programming then do the following (1) select the column (2) right click and select Format Cells (3) Select "Custom" (4) Just Under "Type:" type dd/mm/yyyy hh:mm:ss

    0 讨论(0)
提交回复
热议问题