Converting date and time text to date and time format in Excel










1















Is there any way to format the following text to date and time format in Excel? Nothing I try works.



Fri, November 16 2018 8:00 PM


I have tried doing the following, with no luck.



=TEXT("Fri, November 16 2018 8:00 PM","ddd, mmm d yyyy h:mm AM/PM")









share|improve this question


























    1















    Is there any way to format the following text to date and time format in Excel? Nothing I try works.



    Fri, November 16 2018 8:00 PM


    I have tried doing the following, with no luck.



    =TEXT("Fri, November 16 2018 8:00 PM","ddd, mmm d yyyy h:mm AM/PM")









    share|improve this question
























      1












      1








      1


      0






      Is there any way to format the following text to date and time format in Excel? Nothing I try works.



      Fri, November 16 2018 8:00 PM


      I have tried doing the following, with no luck.



      =TEXT("Fri, November 16 2018 8:00 PM","ddd, mmm d yyyy h:mm AM/PM")









      share|improve this question














      Is there any way to format the following text to date and time format in Excel? Nothing I try works.



      Fri, November 16 2018 8:00 PM


      I have tried doing the following, with no luck.



      =TEXT("Fri, November 16 2018 8:00 PM","ddd, mmm d yyyy h:mm AM/PM")






      excel excel-formula






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 0:23









      user8229029user8229029

      597




      597






















          4 Answers
          4






          active

          oldest

          votes


















          1














          If you want to avoid VBA, then you need to use the DATEVALUE and TIMEVALUE functions. Unfortunately these functions aren't smart enough to convert the text you describe, but you can still split up the text with cell formula prior to inputting into these functions.
          The following formula will convert the text Fri, November 16 2018 8:00 PM to a date/time value (assuming text is in cell A1).



          =DATEVALUE(SUBSTITUTE(MID(A1, FIND(" ",A1)+1, FIND("|", SUBSTITUTE(A1," ","|",4))-FIND(" ",A1)), " ", ", ", 2)) + TIMEVALUE(RIGHT(A1, LEN(A1)-FIND("|", SUBSTITUTE(A1," ","|",4))))





          share|improve this answer























          • This answer is the one I used because it sorts. Thank you.

            – user8229029
            Nov 15 '18 at 2:02


















          1














          You can create your own custom UDF and use it like a worksheet function:



          Public Function myDateToDate(inputRng As Range) As Date

          With CreateObject("VBScript.RegExp")
          .Pattern = "w3,s(w+sd+sd+)s(d+:d+sw+)"
          If .test(inputRng.Value) Then
          With .Execute(inputRng.Value)(0).SubMatches
          myDateToDate = CDate(.Item(0)) + CDate(.Item(1))
          End With
          End If
          End With

          End Function


          This will use Regular Expressions (RegEx) to grab the values in your string, and capture both the date and the time. Since within Excel all a date is is a number, you can add the first capturing group (w+sd+sd+) (which represents the date) with the second capturing group (d+:d+sw+) (which represents the time) together. (See how the regex pattern works here).



          After you have done this, you can now use your newly-created UDF by using the worksheet formula =myDateToDate(A1) - where A1 would be replaced with the cell/string that contains your date.




          enter image description here





          If you are unfamiliar with VBA, read on:




          How do I access the VBE?

          You can gain access to VBE by pressing Alt + F11 while you are inside your workbook.



          Okay, So I have the VBE open. Now how do I apply this Sub/UDF?

          In the left pane you will see your workbook object modules. This is called the Project Explorer. You will need to create a new module, which you can do by right-clicking inside the Project Explorer > Insert > Module:



          enter image description here



          Now you can paste the Sub/UDF to this new module and you are all set!







          share|improve this answer

























          • Thank you, but this solution doesn't sort.

            – user8229029
            Nov 15 '18 at 2:02











          • What do you mean that it doesn't sort? There was no mention of sorting anything in your question.

            – K.Dᴀᴠɪs
            Nov 15 '18 at 2:08


















          1














          A monstrosity but should be locale independent (either US or UK):



          =DATE(LEFT(RIGHT(A1,13),5),MONTH(DATEVALUE(LEFT(MID(A1,6,9),FIND(" ",MID(A1,6,10)))&"1")),MID(MID(A1,FIND(" ",A1)+1,99),FIND(" ",MID(A1,FIND(" ",A1)+1,99))+1,2))+LEFT(TRIM(RIGHT(A1,8)),7)





          share|improve this answer






























            0














            Nice regex solution above, you can also do it in a different way:



            Function ConvertToDate(str As String) As Date

            Dim arr() As String

            arr = Split(str, " ")

            ConvertToDate = CDate(arr(3) & "/" & Month("01/" & arr(1) & "/2018") & "/" & arr(2) & " " & arr(4))

            End Function





            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310753%2fconverting-date-and-time-text-to-date-and-time-format-in-excel%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              If you want to avoid VBA, then you need to use the DATEVALUE and TIMEVALUE functions. Unfortunately these functions aren't smart enough to convert the text you describe, but you can still split up the text with cell formula prior to inputting into these functions.
              The following formula will convert the text Fri, November 16 2018 8:00 PM to a date/time value (assuming text is in cell A1).



              =DATEVALUE(SUBSTITUTE(MID(A1, FIND(" ",A1)+1, FIND("|", SUBSTITUTE(A1," ","|",4))-FIND(" ",A1)), " ", ", ", 2)) + TIMEVALUE(RIGHT(A1, LEN(A1)-FIND("|", SUBSTITUTE(A1," ","|",4))))





              share|improve this answer























              • This answer is the one I used because it sorts. Thank you.

                – user8229029
                Nov 15 '18 at 2:02















              1














              If you want to avoid VBA, then you need to use the DATEVALUE and TIMEVALUE functions. Unfortunately these functions aren't smart enough to convert the text you describe, but you can still split up the text with cell formula prior to inputting into these functions.
              The following formula will convert the text Fri, November 16 2018 8:00 PM to a date/time value (assuming text is in cell A1).



              =DATEVALUE(SUBSTITUTE(MID(A1, FIND(" ",A1)+1, FIND("|", SUBSTITUTE(A1," ","|",4))-FIND(" ",A1)), " ", ", ", 2)) + TIMEVALUE(RIGHT(A1, LEN(A1)-FIND("|", SUBSTITUTE(A1," ","|",4))))





              share|improve this answer























              • This answer is the one I used because it sorts. Thank you.

                – user8229029
                Nov 15 '18 at 2:02













              1












              1








              1







              If you want to avoid VBA, then you need to use the DATEVALUE and TIMEVALUE functions. Unfortunately these functions aren't smart enough to convert the text you describe, but you can still split up the text with cell formula prior to inputting into these functions.
              The following formula will convert the text Fri, November 16 2018 8:00 PM to a date/time value (assuming text is in cell A1).



              =DATEVALUE(SUBSTITUTE(MID(A1, FIND(" ",A1)+1, FIND("|", SUBSTITUTE(A1," ","|",4))-FIND(" ",A1)), " ", ", ", 2)) + TIMEVALUE(RIGHT(A1, LEN(A1)-FIND("|", SUBSTITUTE(A1," ","|",4))))





              share|improve this answer













              If you want to avoid VBA, then you need to use the DATEVALUE and TIMEVALUE functions. Unfortunately these functions aren't smart enough to convert the text you describe, but you can still split up the text with cell formula prior to inputting into these functions.
              The following formula will convert the text Fri, November 16 2018 8:00 PM to a date/time value (assuming text is in cell A1).



              =DATEVALUE(SUBSTITUTE(MID(A1, FIND(" ",A1)+1, FIND("|", SUBSTITUTE(A1," ","|",4))-FIND(" ",A1)), " ", ", ", 2)) + TIMEVALUE(RIGHT(A1, LEN(A1)-FIND("|", SUBSTITUTE(A1," ","|",4))))






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 15 '18 at 1:14









              hughghughg

              1819




              1819












              • This answer is the one I used because it sorts. Thank you.

                – user8229029
                Nov 15 '18 at 2:02

















              • This answer is the one I used because it sorts. Thank you.

                – user8229029
                Nov 15 '18 at 2:02
















              This answer is the one I used because it sorts. Thank you.

              – user8229029
              Nov 15 '18 at 2:02





              This answer is the one I used because it sorts. Thank you.

              – user8229029
              Nov 15 '18 at 2:02













              1














              You can create your own custom UDF and use it like a worksheet function:



              Public Function myDateToDate(inputRng As Range) As Date

              With CreateObject("VBScript.RegExp")
              .Pattern = "w3,s(w+sd+sd+)s(d+:d+sw+)"
              If .test(inputRng.Value) Then
              With .Execute(inputRng.Value)(0).SubMatches
              myDateToDate = CDate(.Item(0)) + CDate(.Item(1))
              End With
              End If
              End With

              End Function


              This will use Regular Expressions (RegEx) to grab the values in your string, and capture both the date and the time. Since within Excel all a date is is a number, you can add the first capturing group (w+sd+sd+) (which represents the date) with the second capturing group (d+:d+sw+) (which represents the time) together. (See how the regex pattern works here).



              After you have done this, you can now use your newly-created UDF by using the worksheet formula =myDateToDate(A1) - where A1 would be replaced with the cell/string that contains your date.




              enter image description here





              If you are unfamiliar with VBA, read on:




              How do I access the VBE?

              You can gain access to VBE by pressing Alt + F11 while you are inside your workbook.



              Okay, So I have the VBE open. Now how do I apply this Sub/UDF?

              In the left pane you will see your workbook object modules. This is called the Project Explorer. You will need to create a new module, which you can do by right-clicking inside the Project Explorer > Insert > Module:



              enter image description here



              Now you can paste the Sub/UDF to this new module and you are all set!







              share|improve this answer

























              • Thank you, but this solution doesn't sort.

                – user8229029
                Nov 15 '18 at 2:02











              • What do you mean that it doesn't sort? There was no mention of sorting anything in your question.

                – K.Dᴀᴠɪs
                Nov 15 '18 at 2:08















              1














              You can create your own custom UDF and use it like a worksheet function:



              Public Function myDateToDate(inputRng As Range) As Date

              With CreateObject("VBScript.RegExp")
              .Pattern = "w3,s(w+sd+sd+)s(d+:d+sw+)"
              If .test(inputRng.Value) Then
              With .Execute(inputRng.Value)(0).SubMatches
              myDateToDate = CDate(.Item(0)) + CDate(.Item(1))
              End With
              End If
              End With

              End Function


              This will use Regular Expressions (RegEx) to grab the values in your string, and capture both the date and the time. Since within Excel all a date is is a number, you can add the first capturing group (w+sd+sd+) (which represents the date) with the second capturing group (d+:d+sw+) (which represents the time) together. (See how the regex pattern works here).



              After you have done this, you can now use your newly-created UDF by using the worksheet formula =myDateToDate(A1) - where A1 would be replaced with the cell/string that contains your date.




              enter image description here





              If you are unfamiliar with VBA, read on:




              How do I access the VBE?

              You can gain access to VBE by pressing Alt + F11 while you are inside your workbook.



              Okay, So I have the VBE open. Now how do I apply this Sub/UDF?

              In the left pane you will see your workbook object modules. This is called the Project Explorer. You will need to create a new module, which you can do by right-clicking inside the Project Explorer > Insert > Module:



              enter image description here



              Now you can paste the Sub/UDF to this new module and you are all set!







              share|improve this answer

























              • Thank you, but this solution doesn't sort.

                – user8229029
                Nov 15 '18 at 2:02











              • What do you mean that it doesn't sort? There was no mention of sorting anything in your question.

                – K.Dᴀᴠɪs
                Nov 15 '18 at 2:08













              1












              1








              1







              You can create your own custom UDF and use it like a worksheet function:



              Public Function myDateToDate(inputRng As Range) As Date

              With CreateObject("VBScript.RegExp")
              .Pattern = "w3,s(w+sd+sd+)s(d+:d+sw+)"
              If .test(inputRng.Value) Then
              With .Execute(inputRng.Value)(0).SubMatches
              myDateToDate = CDate(.Item(0)) + CDate(.Item(1))
              End With
              End If
              End With

              End Function


              This will use Regular Expressions (RegEx) to grab the values in your string, and capture both the date and the time. Since within Excel all a date is is a number, you can add the first capturing group (w+sd+sd+) (which represents the date) with the second capturing group (d+:d+sw+) (which represents the time) together. (See how the regex pattern works here).



              After you have done this, you can now use your newly-created UDF by using the worksheet formula =myDateToDate(A1) - where A1 would be replaced with the cell/string that contains your date.




              enter image description here





              If you are unfamiliar with VBA, read on:




              How do I access the VBE?

              You can gain access to VBE by pressing Alt + F11 while you are inside your workbook.



              Okay, So I have the VBE open. Now how do I apply this Sub/UDF?

              In the left pane you will see your workbook object modules. This is called the Project Explorer. You will need to create a new module, which you can do by right-clicking inside the Project Explorer > Insert > Module:



              enter image description here



              Now you can paste the Sub/UDF to this new module and you are all set!







              share|improve this answer















              You can create your own custom UDF and use it like a worksheet function:



              Public Function myDateToDate(inputRng As Range) As Date

              With CreateObject("VBScript.RegExp")
              .Pattern = "w3,s(w+sd+sd+)s(d+:d+sw+)"
              If .test(inputRng.Value) Then
              With .Execute(inputRng.Value)(0).SubMatches
              myDateToDate = CDate(.Item(0)) + CDate(.Item(1))
              End With
              End If
              End With

              End Function


              This will use Regular Expressions (RegEx) to grab the values in your string, and capture both the date and the time. Since within Excel all a date is is a number, you can add the first capturing group (w+sd+sd+) (which represents the date) with the second capturing group (d+:d+sw+) (which represents the time) together. (See how the regex pattern works here).



              After you have done this, you can now use your newly-created UDF by using the worksheet formula =myDateToDate(A1) - where A1 would be replaced with the cell/string that contains your date.




              enter image description here





              If you are unfamiliar with VBA, read on:




              How do I access the VBE?

              You can gain access to VBE by pressing Alt + F11 while you are inside your workbook.



              Okay, So I have the VBE open. Now how do I apply this Sub/UDF?

              In the left pane you will see your workbook object modules. This is called the Project Explorer. You will need to create a new module, which you can do by right-clicking inside the Project Explorer > Insert > Module:



              enter image description here



              Now you can paste the Sub/UDF to this new module and you are all set!








              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 15 '18 at 1:01

























              answered Nov 15 '18 at 0:54









              K.DᴀᴠɪsK.Dᴀᴠɪs

              7,290112440




              7,290112440












              • Thank you, but this solution doesn't sort.

                – user8229029
                Nov 15 '18 at 2:02











              • What do you mean that it doesn't sort? There was no mention of sorting anything in your question.

                – K.Dᴀᴠɪs
                Nov 15 '18 at 2:08

















              • Thank you, but this solution doesn't sort.

                – user8229029
                Nov 15 '18 at 2:02











              • What do you mean that it doesn't sort? There was no mention of sorting anything in your question.

                – K.Dᴀᴠɪs
                Nov 15 '18 at 2:08
















              Thank you, but this solution doesn't sort.

              – user8229029
              Nov 15 '18 at 2:02





              Thank you, but this solution doesn't sort.

              – user8229029
              Nov 15 '18 at 2:02













              What do you mean that it doesn't sort? There was no mention of sorting anything in your question.

              – K.Dᴀᴠɪs
              Nov 15 '18 at 2:08





              What do you mean that it doesn't sort? There was no mention of sorting anything in your question.

              – K.Dᴀᴠɪs
              Nov 15 '18 at 2:08











              1














              A monstrosity but should be locale independent (either US or UK):



              =DATE(LEFT(RIGHT(A1,13),5),MONTH(DATEVALUE(LEFT(MID(A1,6,9),FIND(" ",MID(A1,6,10)))&"1")),MID(MID(A1,FIND(" ",A1)+1,99),FIND(" ",MID(A1,FIND(" ",A1)+1,99))+1,2))+LEFT(TRIM(RIGHT(A1,8)),7)





              share|improve this answer



























                1














                A monstrosity but should be locale independent (either US or UK):



                =DATE(LEFT(RIGHT(A1,13),5),MONTH(DATEVALUE(LEFT(MID(A1,6,9),FIND(" ",MID(A1,6,10)))&"1")),MID(MID(A1,FIND(" ",A1)+1,99),FIND(" ",MID(A1,FIND(" ",A1)+1,99))+1,2))+LEFT(TRIM(RIGHT(A1,8)),7)





                share|improve this answer

























                  1












                  1








                  1







                  A monstrosity but should be locale independent (either US or UK):



                  =DATE(LEFT(RIGHT(A1,13),5),MONTH(DATEVALUE(LEFT(MID(A1,6,9),FIND(" ",MID(A1,6,10)))&"1")),MID(MID(A1,FIND(" ",A1)+1,99),FIND(" ",MID(A1,FIND(" ",A1)+1,99))+1,2))+LEFT(TRIM(RIGHT(A1,8)),7)





                  share|improve this answer













                  A monstrosity but should be locale independent (either US or UK):



                  =DATE(LEFT(RIGHT(A1,13),5),MONTH(DATEVALUE(LEFT(MID(A1,6,9),FIND(" ",MID(A1,6,10)))&"1")),MID(MID(A1,FIND(" ",A1)+1,99),FIND(" ",MID(A1,FIND(" ",A1)+1,99))+1,2))+LEFT(TRIM(RIGHT(A1,8)),7)






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 15 '18 at 2:18









                  pnutspnuts

                  49k764101




                  49k764101





















                      0














                      Nice regex solution above, you can also do it in a different way:



                      Function ConvertToDate(str As String) As Date

                      Dim arr() As String

                      arr = Split(str, " ")

                      ConvertToDate = CDate(arr(3) & "/" & Month("01/" & arr(1) & "/2018") & "/" & arr(2) & " " & arr(4))

                      End Function





                      share|improve this answer



























                        0














                        Nice regex solution above, you can also do it in a different way:



                        Function ConvertToDate(str As String) As Date

                        Dim arr() As String

                        arr = Split(str, " ")

                        ConvertToDate = CDate(arr(3) & "/" & Month("01/" & arr(1) & "/2018") & "/" & arr(2) & " " & arr(4))

                        End Function





                        share|improve this answer

























                          0












                          0








                          0







                          Nice regex solution above, you can also do it in a different way:



                          Function ConvertToDate(str As String) As Date

                          Dim arr() As String

                          arr = Split(str, " ")

                          ConvertToDate = CDate(arr(3) & "/" & Month("01/" & arr(1) & "/2018") & "/" & arr(2) & " " & arr(4))

                          End Function





                          share|improve this answer













                          Nice regex solution above, you can also do it in a different way:



                          Function ConvertToDate(str As String) As Date

                          Dim arr() As String

                          arr = Split(str, " ")

                          ConvertToDate = CDate(arr(3) & "/" & Month("01/" & arr(1) & "/2018") & "/" & arr(2) & " " & arr(4))

                          End Function






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 15 '18 at 1:15









                          Michal RosaMichal Rosa

                          1,3361815




                          1,3361815



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310753%2fconverting-date-and-time-text-to-date-and-time-format-in-excel%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Kleinkühnau

                              Makov (Slowakei)

                              Deutsches Schauspielhaus