5 Replies Latest reply on Sep 24, 2012 9:27 AM by BruceHerbach

    Dates and Variables

    atlascott

      When someone creates a Task, I give them an option of creating asequence of Tasks that are commonly performed.

       

      They fill out one Task and I script the creation of the other Tasks throug judicious use of the SetField script step.

       

      One that is givng me troubles is the dueDate (date).

       

      I am passing the field dueDate to the variable $duedate.

       

      Then, I create a record and SetField dueDate with calculation $duedate +7. But this does not set the new Task for 7 days after the first Task.

       

      This may be due to variable being data type "text" rather than "date".

       

      I have tried Defining the variable as $duedate = dueDate +7 and then calling $duedate as GetAsDate ($duedate) but it doesn't work.

       

      I have also tried $duedate = dueDate and calling it as a calculation in the SetField as $duedate +7.

       

      Can I pass dates to a variable? if so, how do I get a date back out?

       

      How can I increment the first date by 7 using a means similar to this for the result I am looking for?

       

      I guess I could define 3 more fields in the db, such as dueDate+7 (calculation) = dueDate +7.

       

      But that's creating more data and permanent data storage. There MUST be a better way.

       

      Thanks in advance for any help any can offer. Much appreciated.

        • 1. Re: Dates and Variables
          comment

          atlascott wrote:

           

          I am passing the field  dueDate to the variable $duedate.

           

          Then, I create a record and SetField dueDate with calculation $duedate +7. 

           

          What you describe should work - provided that DueDate is a date field and it contains a valid date.

           

           

           

          atlascott wrote:

           

          But this does not set the new Task for 7 days after the first Task.

           

          Knowing what it does do might help in pinpointing the problem.

           

          Message was edited by: Michael Horak

          • 2. Re: Dates and Variables

            Please be aware that all variables just hold text values (there is NO variable of type date).

             

            I suggest to avoid variables in that context all together - or to work with the numeric representation of the date (or Timestamp) value, like

                   $date = getAsNumber (someDate)

             

            Then you can perform any calculation you want, like

                   newDate = $date + 7

             

            And by the way, you should not worry about "more data storage", only about the number of (unnecessary) fields that  usually lead to confusion later.

             

            Winfried

            • 3. Re: Dates and Variables
              comment

              Winfried Huslik wrote:

               

              Please be aware that all variables just hold text values (there is NO variable of type date).

               

              I know it says "Calculation result must be Text" at the bottom of the calculation window, but that doesn't mean it's true - and indeed it is not. If it were true, these two would be equivalent:

               

              SetVariable [ $d ; Datefield ]

               

              SetVariable [ $t ; GetAsText ( Datefield ) ]

               

              However, there is a BIG difference between them.

              • 4. Re: Dates and Variables
                atlascott

                Thanks, all.

                 

                Of course, doing this kind of work when overtired leads to stupidity like defining a variable like this: $duedate7

                 

                And then calliing it in the script like this $due7

                 

                As a result, nothing works. Duh.

                 

                I fixed it and it all works perfectly now.

                 

                Thanks for the insight and responses, gang.

                 

                Happy Sunday!

                • 5. Re: Dates and Variables
                  BruceHerbach

                  On occasion I have had a script fail when passing a date, time, or time stamp to the script.  Then using it in an if statement.  if $Date = Field::Datetype.  My fix has been to do the comparison using getasX where X would be Date, time to Timestamp.

                   

                  So the comparison would look like:

                  getasDate($DateVariable) = table::Datefield

                   

                  Most of the time this doesn't seem to be nessasary.  However when the variable started in one script then passed to another and then used in a comparison...  I have had the comparison fail.  It was a bit hard to find since looking in the data viewer,  both the field and the variable seem to be a match.  The symptom was the script taking the wrong branch in the if statement.  Using the getasX statement forced filemaker to evaluate matching types and the scripts worked correctly after adding this.

                   

                  Bruce