6 Replies Latest reply on Jul 9, 2012 11:54 AM by timwhisenant

    How to get year only?

    louie23

      In date type, we get the month, date and year. How can I set get year only?

      Thank you.

        • 1. Re: How to get year only?
          wimdecorte

          FM has a "year" function to extract the year from a date.  Since the  year is just a number, if you are going to store that in a date field you will storing a date of Jan 1st of that year.  So you may want to store it in its own number field.

          1 of 1 people found this helpful
          • 2. Re: How to get year only?
            louie23

            Thanks wimdecorte for this helpful advise. Keep it up!

            • 3. Re: How to get year only?
              beverly

              Yes! the Year(date) is a great function for pulling just this value out of another valid date.

              Yes! you can store a Year in a date field and FileMaker thinks for you by putting month=1 and day=2. It may or may not be what you want, but it's a useful feature.

               

              AND...

              You can also format a date so that only the year is shown in the field on the layout.

               

              personally, I like to have a separate number field (auto-enter, perhaps) that is just the year. If I have a field "my_date", then the auto-enter is "Year(my_date)". AND I like to have a yearMonth field (also auto-enter perhaps) used for sorting and grouping - it's a text field, but sorts correctly.

                   yearMonth=GetAsText( Year(my_date) & "_" & Right("00" & Month(my_date); 2) )

               

                   1/1/2010 => 2010_01

              Beverly

              • 4. Re: How to get year only?
                comment

                Beverly Voth wrote:

                 

                Yes! you can store a Year in a date field and FileMaker thinks for you by putting month=1 and day=2. It may or may not be what you want, but it's a useful feature.

                 

                Hmm. My version seems to be lacking this "feature". Entering year only into a date field produces an error message: "The value of this field must be a valid date in the range of years 1 to 4000 and should look like “...”."

                • 5. Re: How to get year only?
                  BruceHerbach

                  As Beverly indicated,  you need to enter values for month and day do that it has a valid date.

                   

                  Depending on the final desired result,  perhaps a text or number field would be a better choice.

                  • 6. Re: How to get year only?
                    timwhisenant

                    Bruce said, “Depending on the final desired result,  perhaps a text or number field would be a better choice.”

                     

                    Also, realize that the Year function referred to by Wim, returns a number type result, not a date type.

                     

                    So I second Bruce’s suggestion that a number field would be a better choice.

                     

                    Tim