creating a unique SKU with code

Hello people,

I’m using code for the creation of products in my store (based on a certain event) but I have some troubles creating a unique sku.

Has anybody an idea or experience how to create a unique sku-number using code (in best case a increasing number starting with the actual year, e.g. 22 0001)?

Many thanks in advance!