Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Converting DateTime to string

    Scheduled Pinned Locked Moved
    Gcode meta commands
    4
    10
    411
    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.
    • jonathanbrentundefined
      jonathanbrent
      last edited by

      Hi Everyone,

      I can't seem to find a way to convert a DateTime variable to a string. I am trying to create a file at the start of my gcode that will include the current date and time (using state.time) in its title; however, it seems that the name of a file must be of type string.

      Any thoughts? Thanks!

      Current Firmware: RepRapFirmware for Duet 3 MB6HC 3.4.6

      dc42undefined T3P3Tonyundefined 2 Replies Last reply Reply Quote 0
      • dc42undefined
        dc42 administrators @jonathanbrent
        last edited by dc42

        @jonathanbrent use the ^ operator to concatenate it with a string literal, even an empty string literal will do.

        Duet WiFi hardware designer and firmware engineer
        Please do not ask me for Duet support via PM or email, use the forum
        http://www.escher3d.com, https://miscsolutions.wordpress.com

        jonathanbrentundefined 1 Reply Last reply Reply Quote 0
        • jonathanbrentundefined
          jonathanbrent @dc42
          last edited by

          @dc42 Thanks! Now it turns out my issue is really that I can't include the ":" character in a file name. Is there a way for me to modify the string that I have retrieved from state.time (e.g. 2024-03-12T12:54:43)? Or is there some other way to get the current time without colons?

          Thanks again

          dc42undefined T3P3Tonyundefined 2 Replies Last reply Reply Quote 0
          • dc42undefined
            dc42 administrators @jonathanbrent
            last edited by

            @jonathanbrent I'm sorry, I can't think of a workaround at present.

            Duet WiFi hardware designer and firmware engineer
            Please do not ask me for Duet support via PM or email, use the forum
            http://www.escher3d.com, https://miscsolutions.wordpress.com

            1 Reply Last reply Reply Quote 0
            • T3P3Tonyundefined
              T3P3Tony administrators @jonathanbrent
              last edited by

              @jonathanbrent can you convert it to an int instead of a string. They the files will be sequential, with the right number of seconds between names. Just not easily human readable without converting the int back to a datetime.

              Being able to use datetime in a filename is a feature I would like as well. There is a feature request tracking something similar here:
              https://github.com/Duet3D/RepRapFirmware/issues/787

              T3P3 created this issue in Duet3D/RepRapFirmware

              closed allow date and time to be retrieved as individual strings/ints #787

              www.duet3d.com

              1 Reply Last reply Reply Quote 0
              • oliofundefined
                oliof
                last edited by

                maybe a generic split function for strings would suffice?

                <>RatRig V-Minion Fly Super5Pro RRF<> V-Core 3.1 IDEX k*****r <> RatRig V-Minion SKR 2 Marlin<>

                T3P3Tonyundefined 1 Reply Last reply Reply Quote 0
                • T3P3Tonyundefined
                  T3P3Tony administrators @oliof
                  last edited by

                  @oliof string split to an array would be even more useful for sure.

                  www.duet3d.com

                  dc42undefined 1 Reply Last reply Reply Quote 0
                  • dc42undefined
                    dc42 administrators @T3P3Tony
                    last edited by

                    @T3P3Tony or maybe a replace-in-string function e.g. replace(state.time, ':', '-')

                    Duet WiFi hardware designer and firmware engineer
                    Please do not ask me for Duet support via PM or email, use the forum
                    http://www.escher3d.com, https://miscsolutions.wordpress.com

                    T3P3Tonyundefined 1 Reply Last reply Reply Quote 1
                    • T3P3Tonyundefined
                      T3P3Tony administrators @dc42
                      last edited by T3P3Tony

                      @dc42 yes that would work as well for the particular usecase of naming a file with a datetime that's a valid filename. Its less generalisable than being able to use just the date or just the time - but that's not necessarily an urgent requirement.

                      It depends on the overhead to implement various types of string handling.

                      www.duet3d.com

                      1 Reply Last reply Reply Quote 0
                      • T3P3Tonyundefined
                        T3P3Tony administrators @jonathanbrent
                        last edited by

                        @jonathanbrent Since 3.6.0beta4 the functions "drop","find" and"take" have been implemented.
                        documentation is here:
                        https://docs.duet3d.com/User_manual/Reference/Gcode_meta_commands#functions
                        I have updated this github issue with an example of how to use them for date/time splitting into a string.

                        https://github.com/Duet3D/RepRapFirmware/issues/787#issuecomment-2658795794

                        T3P3 created this issue in Duet3D/RepRapFirmware

                        closed allow date and time to be retrieved as individual strings/ints #787

                        www.duet3d.com

                        1 Reply Last reply Reply Quote 0
                        • T3P3Tonyundefined T3P3Tony referenced this topic
                        • First post
                          Last post
                        Unless otherwise noted, all forum content is licensed under CC-BY-SA