How can give expirey date using scientific way?
First, when developing (R'n'D) your product, you must decide how long you want your product to last, a few days? couple of weeks, months ? 

You then engineer your recipes to make it so; different recipe variations, different packaging methods ... 

Then you need to find a food testing laboratory to help you test your product at different times to se how well your product lasts at different times.

At those different times, the product will be tested for any kind of degradation and/or microbacterial growth, mold, texture and taste/smell defects

Then with all the data, you can decide the expiry dates taking into account all of that.

https://haccpmentor.com/labelling/how-to-set-your-food-expiry-date/

https://lifehacker.com/how-food-manufacturers-pick-expiration-dates-and-what-t-1782752993

https://www.fsis.usda.gov/wps/portal/fsis/topics/food-safety-education/get-answers/food-safety-fact-sheets/food-labeling/food-product-dating/food-product-dating