7 Replies Latest reply on Dec 19, 2012 1:55 AM by NaturSalus

    End Date Wrongly Calculated

    NaturSalus

      Title

      End Date Wrongly Calculated

      Post

           Hello,

           I have a Trial Expiry script than on open from a lockdown state compares the Current date to the End date.

           When I set up the Start and End Trial dates the "unsafe" way, that is using Get (Current Date) to determine the Start date and from taht the End date, the script behaves as expected. 

           ...

            

           Else If [ IsEmpty ( zRESOURCES::gEndDate ) ]
            
           Set Field [ zRESOURCES::gEndDate; Get ( CurrentDate ) + 20 ]
            
           Set Field [ zRESOURCES::gStartDate; Get ( CurrentDate ) ]
            
           Show Custom Dialog [ Message: "This demo will expire in 20 days"; Buttons: “OK”, “Cancel” ]
           Exit Script [ ]

           ...

           However, when I set it up the "safe" way, that is the developer enters the Trial Start date in the ZRESOURCES::gTrialStartDate field and the Trial Expiry script contains the following script steps:

            

           ...
           Else If [ IsEmpty ( zRESOURCES::gEndDate ) ]
            
           Set Field [ zRESOURCES::gEndDate; zRESOURCES::gTrialStartDate + 20 ]
            
           Show Custom Dialog [ Message: "This demo will expire in 20 days"; Buttons: “OK”, “Cancel” ]
            
           Exit Script [ ]Set Field [ zRESOURCES::gStartDate; zRESOURCES::gTrialStartDate ]
           ...

            

            

           the generated End date makes no sense and on the second start up the user gets the messsage: "Trial period has expired"

           So for a zRESOURCES::gTrialStartDate of 18/12/2012 ( this is the date format on my machine under MS Windows 7 OS in Spain) the generated zRESOURCES::gEndDate is 20/01/0001

            

           Somehow the date format for Spain and for most European countries dd/mm/yyyy is misinterpreted by FM 11 when used in a calculation.

           Any clues how to sort it out so that I can use the "safe" way to set up Sart and End dates for the trial period of my runtime?

            

           Thanks,

            

           naturalsus

            

        • 1. Re: End Date Wrongly Calculated
          philmodjunk

               Dates used in calculations are treated as numbers, the format used to display the result or to input the value should have no effect on how the expression evaluates.

               I do see one thing odd in your sample script:

               Show Custom Dialog [ Message: "This demo will expire in 20 days"; Buttons: “OK”, “Cancel” ]
          Exit Script [ ]
               Set Field [ zRESOURCES::gStartDate; zRESOURCES::gTrialStartDate ]
                
               As written, the last set field step, the one to asssign a date to gStartDate is never executed.
          • 2. Re: End Date Wrongly Calculated
            NaturSalus

                 Hello Phil,

                 You are right, it's my mistake

                 where I said:

                  

                 Else If [ IsEmpty ( zRESOURCES::gEndDate ) ]
                  
                 Set Field [ zRESOURCES::gEndDate; zRESOURCES::gTrialStartDate + 20 ]
                  
                 Show Custom Dialog [ Message: "This demo will expire in 20 days"; Buttons: “OK”, “Cancel” ]
                  
                 Exit Script [ ]Set Field [ zRESOURCES::gStartDate; zRESOURCES::gTrialStartDate ]
                  
                  
                 I meant:
                  
                      Else If [ IsEmpty ( zRESOURCES::gEndDate ) ]
                       
                      Set Field [ zRESOURCES::gEndDate; zRESOURCES::gTrialStartDate + 20 ]
                       
                      Set Field [ zRESOURCES::gStartDate; zRESOURCES::gTrialStartDate ]
                       
                      Show Custom Dialog [ Message: "This demo will expire in 20 days"; Buttons: “OK”, “Cancel” ]
                       
                      Exit Script [ ]
                  

            Dates used in calculations are treated as numbers, the format used to display the result or to input the value should have no effect on how the expression evaluates.

                 Well, I enter the Start date on the zRESOURCES::gStartDate field as a date.

            Then I logout without exiting the runtime and check the value in the  zRESOURCES::gEndDate field and what I see is: 20/01/0001

            Then if I exit the runtime and try to get into it I get the message "Trial period has expired" and I can no longer enter it even with the admin account. So I have to dump it and start from another runtime that has off the Expiry Trial script 

                 Sometime ago I red something about problems with the date format mm/dd/yyyy native to FM and others like dd/mm/yyyy but I don't remember what was the right fix.

            • 3. Re: End Date Wrongly Calculated
              philmodjunk

                   Make sure that gStartDate is a field of type date, not text or number.

                   When you got the result of 20/01/001, what date did you enter into gStartDate?

                   Have you tried this debugging excersize?

                   Create a runtime that includes the admin account just for testing purposes.

                   Launch FileMaker Advanced without opening the run time. Enable the script debugger and data viewer. Then use File from the file menu to open the run time file--entering the admin account/password when asked to do so. Step through your script carefully watching the field values change and checking key calculations via the "watch" tool in the data viewer.

                   That may help you spot where this is going wrong.

              • 4. Re: End Date Wrongly Calculated
                NaturSalus

                Make sure that gStartDate is a field of type date, not text or number.

                 zRESOURCES::gStartDate (Date) Data formatting: Date. As entered

                When you got the result of 20/01/001, what date did you enter into gStartDate?

                18/12/2012

                      

                Have you tried this debugging excersize?

                Create a runtime that includes the admin account just for testing purposes.

                Launch FileMaker Advanced without opening the run time. Enable the script debugger and data viewer. Then use File from the file menu to open the run time file--entering the admin account/password when asked to do so. Step through your script carefully watching the field values change and checking key calculations via the "watch" tool in the data viewer.

                That may help you spot where this is going wrong.

                      

                     I try to see what I am getting and I'll let you know.

                      

                     Thanks

                      

                • 5. Re: End Date Wrongly Calculated
                  philmodjunk
                       

                  zRESOURCES::gStartDate (Date) Data formatting: Date. As entered

                       Please check this in Manage | Database | Fields, not on the Data tab, as we need to know how this data is stored, not how it is formatted.

                       Check your calculation where you add 20 days. The date you are getting is consistent for what you get when you add 20 to a date field with 0 in the start date field. Also make sure that access permissions permit accessing the value of this field.

                  • 6. Re: End Date Wrongly Calculated
                    NaturSalus

                         Hello Phil,

                          

                    Please check this in Manage | Database | Fields, not on the Data tab, as we need to know how this data is stored, not how it is formatted.

                    As I said before:

                         the  zRESOURCES::gStartDate field is a date type:  zRESOURCES::gStartDate (Date) Data formatting: Date. As entered

                         and is formated as a date type:  zRESOURCES::gStartDate (Date) Data formatting: Date. As entered

                          

                          

                    Have you tried this debugging excersize?

                    Create a runtime that includes the admin account just for testing purposes.

                    Launch FileMaker Advanced without opening the run time. Enable the script debugger and data viewer. Then use File from the file menu to open the run time file--entering the admin account/password when asked to do so. Step through your script carefully watching the field values change and checking key calculations via the "watch" tool in the data viewer.

                    That may help you spot where this is going wrong.

                          

                         I hadn't degubbed my runtime, big mistake!

                         During debugging  I found out that the Privilege Set settings for the Lockdown state needed to be modified.

                          

                    Also make sure that access permissions permit accessing the value of this field.

                    This was the problem.

                          

                         Thank you for the tip about how to do a debugging of a runtime. From now on all my projects will go through this process.

                         natursalus

                          

                    • 7. Re: End Date Wrongly Calculated
                      NaturSalus

                           Hello Phil,

                           I almost forgot it:

                            

                           Merry Christmas and a Happy New Year 2013 for you and your family!

                            

                           natursalus