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

Converting DateTime to string

Scheduled Pinned Locked Moved
Gcode meta commands
4
10
395
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.
  • undefined
    jonathanbrent
    last edited by 12 Mar 2024, 18:20

    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

    undefined undefined 2 Replies Last reply 12 Mar 2024, 18:32 Reply Quote 0
    • undefined
      dc42 administrators @jonathanbrent
      last edited by dc42 3 Dec 2024, 18:33 12 Mar 2024, 18:32

      @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

      undefined 1 Reply Last reply 12 Mar 2024, 18:57 Reply Quote 0
      • undefined
        jonathanbrent @dc42
        last edited by 12 Mar 2024, 18:57

        @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

        undefined undefined 2 Replies Last reply 15 Mar 2024, 09:42 Reply Quote 0
        • undefined
          dc42 administrators @jonathanbrent
          last edited by 15 Mar 2024, 09:42

          @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
          • undefined
            T3P3Tony administrators @jonathanbrent
            last edited by 19 Mar 2024, 00:16

            @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 24 Apr 2023, 19:55 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
            • undefined
              oliof
              last edited by 19 Mar 2024, 08:29

              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<>

              undefined 1 Reply Last reply 19 Mar 2024, 09:39 Reply Quote 0
              • undefined
                T3P3Tony administrators @oliof
                last edited by 19 Mar 2024, 09:39

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

                www.duet3d.com

                undefined 1 Reply Last reply 19 Mar 2024, 15:37 Reply Quote 0
                • undefined
                  dc42 administrators @T3P3Tony
                  last edited by 19 Mar 2024, 15:37

                  @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

                  undefined 1 Reply Last reply 19 Mar 2024, 15:44 Reply Quote 1
                  • undefined
                    T3P3Tony administrators @dc42
                    last edited by T3P3Tony 19 Mar 2024, 15:44

                    @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
                    • undefined
                      T3P3Tony administrators @jonathanbrent
                      last edited by 14 Feb 2025, 10:02

                      @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 24 Apr 2023, 19:55 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
                      • undefined T3P3Tony referenced this topic 14 Feb 2025, 10:02
                      • First post
                        Last post
                      Unless otherwise noted, all forum content is licensed under CC-BY-SA