Community
    • Login

    New to Notepad++ and trying to convert 12 hour time to 24

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 242 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Matt LongM Offline
      Matt Long
      last edited by

      Good Afternoon

      I am new to Notepad++ and I am trying to write a script to convert 12 hour time into 24 hour time format. Below is the data string that I have to convert:

      01-May-26 12:15:00 AM,689.1,WESTHAMPTON_HALL_Elec

      This is just one string out of 600+ but I ultimately need them all to read like:

      5/1/2026 00:15,689.1,WESTHAMPTON_HALL_Elec

      Any assistance is much appreciated!

      CoisesC 1 Reply Last reply Reply Quote 0
      • CoisesC Offline
        Coises @Matt Long
        last edited by Coises

        @Matt-Long said:
        I am new to Notepad++ and I am trying to write a script to convert 12 hour time into 24 hour time format. Below is the data string that I have to convert:

        01-May-26 12:15:00 AM,689.1,WESTHAMPTON_HALL_Elec

        This is just one string out of 600+ but I ultimately need them all to read like:

        5/1/2026 00:15,689.1,WESTHAMPTON_HALL_Elec

        The Timestamps… command in the Columns++ plugin can help with this.

        For conversion you want, you would select day-month-year in the From date and time section, then select Custom in the To date and time section, enter M/d/yyyy HH:mm as the custom picture, check Overwrite selection, then click To Date/Time to perform the conversion.

        To use this, you need to have all the timestamps lined up in a column and make a column selection. If your document has a series of lines like the example you gave with all three-character months, you can select it as is.

        If you have months spelled out, so that the right edge of the column doesn’t line up, you can use a regular expression to change the first comma to a tab, enable Elastic tabstops on the Columns++ menu, and then you can select the column, perform the conversion, and use another regular expression to convert the tabs back to commas. (Alternatively, if this is a CSV file, you can use the Conversion functions in Columns++ to convert from comma separated values to tabs and back again instead of using regular expressions.)

        If the timestamps don’t occur in contiguous column at all, we might have to devise a more inventive method of getting them into a column selection if you want to use Columns++ to do the conversion.

        For an explanation of how to make a column selection, see:
        https://npp-user-manual.org/docs/editing/#entering-column-mode

        For an explanation of how to install a plugin from the plugins list (Columns++ is in the list), see:
        https://npp-user-manual.org/docs/plugins/#install-using-plugins-admin

        1 Reply Last reply Reply Quote 2
        • guy038G Offline
          guy038
          last edited by guy038

          Hi, @matt-long, @coises and All,

          Of course, the @coises’s plugin would be the best solution, being both flexible and powerful

          However, @matt-long, if you don’t want to install any new plugin, here is a solution with native N++ only !

          Of course, I’ll use the part of file which ONLY needs changes. But, in your personal file, the trailing part of each line will stay unchanged !


          So, let’s suppose an INPUT text, like below, pasted in a new tab :

          09-Jan-26 00:00:00 AM,
          13-Sep-21 02:00:59 AM,
          13-Jul-24 04:57:29 AM,
          19-Apr-20 07:42:50 AM,
          01-Mar-26 09:12:43 AM,
          29-Feb-24 11:08:51 AM,
          25-Jul-23 11:59:59 AM,
          09-Jan-19 12:00:00 AM,
          01-May-26 00:00:00 PM,
          08-Oct-25 02:54:31 PM,
          17-Feb-22 03:29:35 PM,
          23-Sep-18 06:37:06 PM,
          03-Nov-20 08:55:44 PM,
          31-Aug-26 10:38:00 PM,
          31-Dec-20 11:59:59 PM,
          01-May-26 12:00:00 PM,
          
          • Open the Replace dialog

          • Uncheck all box options

          • FIND (?-si)^(0(\d)|\d\d)-(.+?)-(\d\d) (\d\d):(\d\d):\d\d (AM|PM)(?=,)

          • REPLACE (?2\2:\1)/\3/(?{4}20\4) \5\7:\6

          • Check the Wrap around option

          • Select the Regular expression search mode

          • Click on the Replace All button

          => You should obtain the temporary OUTPUT text below :

          9/Jan/2026 00AM:00,
          13/Sep/2021 02AM:00,
          13/Jul/2024 04AM:57,
          19/Apr/2020 07AM:42,
          1/Mar/2026 09AM:12,
          29/Feb/2024 11AM:08,
          25/Jul/2023 11AM:59,
          9/Jan/2019 12AM:00,
          1/May/2026 00PM:00,
          8/Oct/2025 02PM:54,
          17/Feb/2022 03PM:29,
          23/Sep/2018 06PM:37,
          3/Nov/2020 08PM:55,
          31/Aug/2026 10PM:38,
          31/Dec/2020 11PM:59,
          1/May/2026 12PM:00,
          

          Now, APPEND at the very end of your file, all the lines below :

          #Jan 1
          #Feb 2
          #Mar 3
          #Apr 4
          #May 5
          #Jun 6
          #Jul 7
          #Aug 8
          #Sep 9
          #Sept 9
          #Oct 10
          #Nov 11
          #Dec 12
          #00AM 00
          #01AM 01
          #02AM 02
          #03AM 03
          #04AM 04
          #05AM 05
          #06AM 06
          #07AM 07
          #08AM 08
          #09AM 09
          #10AM 10
          #11AM 11
          #12AM 12
          #00PM 12
          #01PM 13
          #02PM 14
          #03PM 15
          #04PM 16
          #05PM 17
          #06PM 18
          #07PM 19
          #08PM 20
          #09PM 21
          #10PM 22
          #11PM 23
          #12PM 00
          

          Thus, your INPUT text is now as below :

          9/Jan/2026 00AM:00,
          13/Sep/2021 02AM:00,
          13/Jul/2024 04AM:57,
          19/Apr/2020 07AM:42,
          1/Mar/2026 09AM:12,
          29/Feb/2024 11AM:08,
          25/Jul/2023 11AM:59,
          9/Jan/2019 12AM:00,
          1/May/2026 00PM:00,
          8/Oct/2025 02PM:54,
          17/Feb/2022 03PM:29,
          23/Sep/2018 06PM:37,
          3/Nov/2020 08PM:55,
          31/Aug/2026 10PM:38,
          31/Dec/2020 11PM:59,
          1/May/2026 12PM:00,
          #Jan 1
          #Feb 2
          #Mar 3
          #Apr 4
          #May 5
          #Jun 6
          #Jul 7
          #Aug 8
          #Sep 9
          #Sept 9
          #Oct 10
          #Nov 11
          #Dec 12
          #00AM 00
          #01AM 01
          #02AM 02
          #03AM 03
          #04AM 04
          #05AM 05
          #06AM 06
          #07AM 07
          #08AM 08
          #09AM 09
          #10AM 10
          #11AM 11
          #12AM 12
          #00PM 12
          #01PM 13
          #02PM 14
          #03PM 15
          #04PM 16
          #05PM 17
          #06PM 18
          #07PM 19
          #08PM 20
          #09PM 21
          #10PM 22
          #11PM 23
          #12PM 00
          
          • Open again the Replace dialog

          • Uncheck all box options

          • FIND (?-si)(?|(\u\l\l|Sept)|(\d\d(?:AM|PM)))(?=(?s).+^#\1 (\d+))|(?s)^#.+

          • REPLACE \2

          • Check the Wrap around option

          • Select the Regular expression search mode

          • Click on the Replace All button

          => You should get your expected OUTPUT text :

          9/1/2026 00:00,
          13/9/2021 02:00,
          13/7/2024 04:57,
          19/4/2020 07:42,
          1/3/2026 09:12,
          29/2/2024 11:08,
          25/7/2023 11:59,
          9/1/2019 12:00,
          1/5/2026 12:00,
          8/10/2025 14:54,
          17/2/2022 15:29,
          23/9/2018 18:37,
          3/11/2020 20:55,
          31/8/2026 22:38,
          31/12/2020 23:59,
          1/5/2026 00:00,
          

          Voila !

          Best Regards,

          guy038

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors