For WW1, a good starting point would be to post your grandfather's name. From that, it is possible that a record could be compiled of the units to which he was assigned, and the corresponding dates. (It is always surprising to find out how much information has been accumulated by the various members of this forum.) If he ever shot down an enemy aircraft, or was himself shot down, there's a fair chance that the names of all the participants can be determined. It's rather like pulling on a loose thread, and suddenly there is a massive tangle of yarn at your feet!
For WW2, contact the appropriate branch of service records center.