9 Replies Latest reply on Jan 29, 2009 5:19 PM by ERIKCHAN

    date_field year equal to current year

    ERIKCHAN

      Title

      date_field year equal to current year

      Post

      I have a field store date call date_field. The date_field format is yyyy/mm/dd. I want to know how to calculate date_field year equal to current year.

      I know that I can use YEAR(date_field) to get year.
      But when I write a script in edit script window.
      I choose the date_field.
      Then how can I input the formula.

      I tried to input
      YEAR(date_field) ; Year(GET(CurrentDate))
      in Calculated Result: Specify window.

      But that have error message
      "An operator (e.g. +, -, ", ...( is expected here.)"

      How can I do?







        • 1. Re: date_field year equal to current year
          ninja
            

          howdy Erik,

          Thanks for the post!

           

          Date_field_year should be a field that is set up to be a calculation under File>Define>Database

           

          The calculation you would use under "Specifiy" would simply be "Year(date_field)" without the quotes.

           

          Also pay attention to the "Calculation must result in" dropdown at the bottom of the "Specify" window.

           

          Is that what you're after?

          • 2. Re: date_field year equal to current year
            ERIKCHAN
              

            THANKS FOR NINJA.

            Yes, you are right.

            If I add date_field_year in table. I can fulfill my request.

             

            But the problem is the database is not me. If that have method to find all current year records by using date_field. That is wonferful.

            Anyone have another suggestion to help me?

            • 3. Re: date_field year equal to current year
              Orlando
                

              Hi Erik 

               

              Are you trying to convert the date in your date_field to be the same date, but current year i.e. 2008/01/22 will become 2009/01/22.

               

              or are you trying to perform a find in the database that will result in a found set where of all records in the database where the date_field equals the current year.

               

              Also the date format you are using yyyy/mm/dd is that the format FileMaker inserts or are you manually inputting the date? 

              • 4. Re: date_field year equal to current year
                ERIKCHAN
                  

                Yes, I am trying to perform a find in the database that will result in a found set where of all records in the database where the date_field equals the current year.

                 

                The date format maybe I typed wrong. But I think that is not important.

                 

                I know that the formula is...

                YEAR(date_field) ; Year(GET(CurrentDate))

                But how can I input it in script window?

                Or you have another method to do it?

                • 5. Re: date_field year equal to current year
                  Orlando
                    

                  OK What you want to do is create a script that does the following

                   

                  #
                  Enter Find Mode []
                  Set Field [ date_field ; Year ( Get CurrentDate ) ]
                  Perform Find []
                  #

                   

                  So looking at your original post you may be setting up the Set Field step wrong.

                   

                  Specify the Set Field script step in the Edit Scripts window and where it says "Specify Target Field" click on Specify and in the dialog that pops up select your date_field field and click 'OK'

                   

                  Then click 'Specify' next to the "Calculated Results" label and in the Specify Calculation dialog that pops up input teh following

                   

                  Year ( Get CurrentDate )

                   

                  Also with the Enter Find Mode script step make sure to deselect the option to Pause.

                   

                  Let us know how you get on with this. 

                  • 6. Re: date_field year equal to current year
                    ERIKCHAN
                      

                    OK, I remember that I used to try it before and doesn't work.

                    I will try this one again tomorrow when I come back to office.

                     

                    Anyway, THANKS~

                    • 7. Re: date_field year equal to current year
                      Orlando
                         Also worth double checking that your date_field is set to Field Type: Date.
                      • 8. Re: date_field year equal to current year
                        ninja
                          

                        Erik,

                         

                        If what you are trying to do is find all records that have the current year's date on them, then the above solutions will work...

                         

                        To find by your calculated "year" field, use the script:

                        Enter Find Mode

                        Set Field[date_feild_year;Year(Get(CurrentDate))]

                        Perform Find

                         

                        Are you setting your date_field during the find, or are you setting the date_field_year that captured only the year?  It makes a big difference.

                         

                         

                        • 9. Re: date_field year equal to current year
                          ERIKCHAN
                            

                          That say.

                          I only can make a field to store date_field_year to match current year to fulfill my request?

                           

                          THANKS~