• Login
Community
  • Login

Today's date instead of YYYYMMDD

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 2 Posters 536 Views
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.
  • Y
    Yves Davignon
    last edited by Mar 16, 2023, 1:19 PM

    Good day,

    I have a notepad++ file that I copy and paste from on a daily basis.

    I have this line:
    COPY TO .\lcpout\Removed-Mar2023\REMOVED-YYYYMMDD

    I manually replace the YYYYMMDD with today’s date but is there a way to have the YYYYMMDD reflect today’s date instead of the place holder?

    Tx for your help,

    Yves

    A 1 Reply Last reply Mar 16, 2023, 1:43 PM Reply Quote 0
    • A
      Alan Kilborn @Yves Davignon
      last edited by Mar 16, 2023, 1:43 PM

      @Yves-Davignon

      e1721c30-b389-4c1f-bbdc-22f681d4d888-image.png

      1 Reply Last reply Reply Quote 1
      • Y
        Yves Davignon
        last edited by Mar 16, 2023, 2:18 PM

        Tx Alan,

        That will indeed insert today’s date where the cursor is located.

        What I am/was looking for is a Date variable that I could insert in my file and when the notpad++ file is open, that date is populated with today’s date. If it can be done of course.

        Yves

        A 1 Reply Last reply Mar 16, 2023, 2:43 PM Reply Quote 0
        • A
          Alan Kilborn @Yves Davignon
          last edited by Mar 16, 2023, 2:43 PM

          @Yves-Davignon

          Ah. So you mean that at the time of file opening, you want to do a replace on YYYYMMDD with the current date. Gotcha.

          That would be fairly easy to script if you are willing to use a scripting plugin? More detail on what would be required for that is HERE.

          1 Reply Last reply Reply Quote 1
          • A
            Alan Kilborn
            last edited by Mar 16, 2023, 3:20 PM

            Anyway, here’s a demo script that could accomplish the goal. I call it ReplaceYyyymmddOnFileOpen.py:

            # -*- coding: utf-8 -*-
            
            # references:
            #  https://community.notepad-plus-plus.org/topic/24257
            
            #-------------------------------------------------------------------------------
            
            from Npp import *
            import time
            
            #-------------------------------------------------------------------------------
            
            class RYOFO(object):
            
                def __init__(self):
                    notepad.callback(self.fileopened_callback, [NOTIFICATION.FILEOPENED])
                    notepad.callback(self.bufferactivated_callback, [NOTIFICATION.BUFFERACTIVATED])
                    self.process_next_buf_act = False
            
                def fileopened_callback(self, args):
                    self.process_next_buf_act = True
            
                def bufferactivated_callback(self, args):
                    if self.process_next_buf_act:
                        editor.replace('YYYYMMDD', time.strftime('%Y%m%d', time.localtime()))
                        self.process_next_buf_act = False
            
            #-------------------------------------------------------------------------------
            
            try:
                ryofo
            except NameError:
                ryofo = RYOFO()
            
            1 Reply Last reply Reply Quote 5
            • A Alan Kilborn referenced this topic on Mar 16, 2023, 3:20 PM
            1 out of 5
            • First post
              1/5
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors