Each National Governing Body (in the United States it is USMS) establishes their own standard for establishing the age of the swimmer.
In the USA the rules state:
102.2. AGE DETERMINING DATE
102.2.1—For short course yards, the eligibility of a participant for a particular age group shall be determined by the age as of the last day of the meet.
102.2.2—For short course meters and long course meters, the eligibility of a participant for a particular age group shall be determined by the age as of December 31 of the year of competition.
For FINA (the world governing body) their rule states:
MSW 2 Age Determining Date
For all purposes pertaining to Masters World Records and Masters World Championships meet competition, the actual attained age of the competitor shall be determined as of December 31st of the year of competition.
You will typically find that each country will conform to FINA rules for meets run in Meter pools. If in doubt, check with the meet director. Also, the eligibility date rules are often on the entry form. Something like “enter your age as of 12/31/02”.