How to add time/date/trigger to a specific code?

Welcome to the forum

Do you want to know the actual time of the event, in which case you will need a source for the time such as a Real Time Clock (RTC), or the time relative to some previous event, in which case you could use millis() or an RTC

Which Arduino board do you have ?
If it is WiFi enabled then you could consider getting the time from the Internet