Excel Date to String conversion

前端 未结 9 617
野趣味
野趣味 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 22:11

    I have no idea about the year of publication of the question; it might be old now. So, I expect my answer to be more of a reference for future similar questions after my post.

    I don't know if anybody out there has already given an answer similar to the one I am about to give, which might result -I think- being the simplest, most direct and most effective: If someone has already given it, I apologize, but I haven't seen it. Here, my answer using CStr instead of TEXT:

    Asuming cell A1 contains a date, and using VBA code:

    Dim strDate As String
    
    'Convert to string the value contained in A1 (a date)
    strDate = CStr([A1].Value)
    

    You can, thereafter, manipulate it as any ordinary string using string functions (MID, LEFT, RIGHT, LEN, CONCATENATE (&), etc.)

    0 讨论(0)
  • 2020-11-28 22:12
    =TEXT(A1,"DD/MM/YYYY hh:mm:ss")
    

    (24 hour time)

    =TEXT(A1,"DD/MM/YYYY hh:mm:ss AM/PM")
    

    (standard time)

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

    In some contexts using a ' character beforehand will work, but if you save to CSV and load again this is impossible.

    '01/01/2010 14:30:00
    
    0 讨论(0)
提交回复
热议问题