8 Replies Latest reply on Jan 8, 2013 5:02 PM by Stephen Huston

    Script to save by date

    jcgrafted

      I am using FileMaker Pro 11.

       

      I am writing a script to do an export. I want the export to save the filename as the current date. I cannot seem to find how to do this. I see in the script option "Export Records" that you can use a variable as the file path and name. I also see the option to "Set Variable" but I cannot seem to make it hold the date as part of the variable.

       

      I am trying to set the variable to include the file path, the date (in yyyy-mm-dd format), and the file type. (IE "S:/MeetingsAndContactsDatabase/OldImports/2013/2013-01-03.xls")

       

      Please help.

        • 1. Re: Script to save by date
          StephenWonfor

          Hi

           

          SetVariable($Output; "S:/MeetingsAndContactsDatabase/OldImports/2013/" & year(get(currentdate) & "-" & month(get(currentdate) & "-" & day(get(currentdate) & ".xls")



          Stephen

          • 2. Re: Script to save by date
            StephenWonfor

            Hi

             

            I suppose it could be more elegant.

             

            You could set the global variables on log in, then simply refer to them later.

             

            SetVariable($$Date; year(get(currentdate)) & "-" & month(get(currentdate)) & "-" &day(get(currentdate))

            SetVariable($$Year; year(get(currentdate))

            SetVariable($$Filepath; "S:/MeetingsAndContactsDatabase/OldImports/"

             

             

            SetVariable($Output; $$Filepath & $$Year & "/" & $$Date & ".xls")

             

            Stephen


            1 of 1 people found this helpful
            • 3. Re: Script to save by date
              keywords

              Better still, use the following:

               

              SetVariable (

               

              Let( [

               

              today = get ( currentdate ) ;

              theDate = year ( today ) & "-" & month ( today ) & "-" & day ( today ) ;

              theYear = year ( today ) ;

              theFilepath = "S:/MeetingsAndContactsDatabase/OldImports/" ] ;

               

              $Output = theFilepath & theYear & "/" & theDate & ".xls" )


              No global variables to manage this way.

              • 4. Re: Script to save by date
                Stephen Huston

                You might also consider padding the date pieces for day and month with a leading Zero and having it choose

                Right characters (2) so that each day and month is 2 digits long regardless of the date involved. That adds a level of consistency that is really important if you eventually save a bunch of these files in a common directory and want to sort them by name with only the date-code to differentiate them.

                1 of 1 people found this helpful
                • 5. Re: Script to save by date
                  StephenWonfor

                  Stephen

                   

                  I think this one is from Ray Cologon.

                   

                  year($Date) * 10^4 + month($Date) * 10^2 + day($Date)

                   

                  Does the same thing but more elegance.

                   

                  Stephen

                  • 6. Re: Script to save by date
                    Stephen Huston

                    Elegance is nice. I like it.

                    It's important that the developer using it writes it so they can understand what it does later; some of these CFs require commenting to make sure the user can tell what's going on months/years later when they wonder: why I am using this, and what does it do?

                    • 7. Re: Script to save by date
                      jcgrafted

                      Thanks for all the help.  Here is what finally worked:

                       

                      Set Variable [$$Date; Value:Year(Get(CurrentDate)) & "-" &  Right ( "0" & Month ( Get(CurrentDate) ) ; 2 ) & "-" &  Right ( "0" & Day ( Get(CurrentDate) ) ; 2 )]

                       

                      Set Variable [$$Year; Value:Year(Get(CurrentDate))]

                      Set Variable [$$Filepath; Value:"filewin:/S:/MeetingsAndContactsDatabase/OldImports/"]

                      Set Variable [$Output; Value:$$Filepath & $$Year & "/" & $$Date & ".xls"]

                      Export Records["$Output"; Unicode(UTF-16)]

                       

                      The file path had to include "filewin".

                       

                      I apreciate the reminder to use two digit month and day but could not get StephenWonfor's code to work. I did a forum search for two digit month.

                      • 8. Re: Script to save by date
                        Stephen Huston

                        jcgrafted wrote, in part:

                         

                        The file path had to include "filewin".

                        There are some custom functions and OS calculation tests which let you set the filepath so it will be cross-platform compatible, but your solution will work as long as the file is only used with Windows clients.