This April 2017 video says about itself:
Genetics Used To Pinpoint When Early Mammals Became Nocturnal
Using genetic analysis of modern species, researchers have confirmed what has long been assumed to be the case – the early mammals that evolved when dinosaurs were roaming the land became nocturnal early on, most likely to avoid the reptiles that were snacking on them.
“This method is like using the genome as a fossil record, and with it we’ve shown when genes involved in night vision appear”, says Liz Hadly, co-author of the study published in Scientific Reports, in a statement.
From the University of Chicago Press Journals in the USA:
Did early mammals turn to night life to protect their sperm?
October 15, 2019
Humans are diurnal — we are active in the day and sleep at night. But diurnalism is by far the exception rather [than] the rule in mammals. About 250-230 million years ago, the mammalian ancestors, called the therapsids, became exclusively nocturnal, and stayed so until the demise of the dinosaurs 66 million years ago. All of our mammal ancestors lived in the dark for about 200 [million] years, and the majority still do to this day. Humans are, essentially, nocturnal animals that have reverted back to living in the sun.
There has been much speculation about why the therapsids became nocturnal. The traditional argument is that the archosauriforms and the dinosaurs became ecologically dominant during the Triassic. To avoid being eaten by the multitude of new carnivorous reptiles, the archaic mammals, it is argued, fled into the dark, where reptiles had yet to dominate. In a new paper, “Obligatory nocturnalism in Triassic archaic mammals: Preservation of sperm quality?”, Barry G. Lovegrove proposes a simple, new, alternative hypothesis based purely upon physiological constraints.
The therapsids were becoming rapidly endothermic (producing more of their own internal heat through metabolism) to fuel new energy demands and to defend the consequent elevated body temperature, especially as they got smaller during the Triassic. And herein lies a problem. As their body temperature started to approach that of the air, around 93.2°F (34°C), they would not have been able to offload excessive heat generated by being active during the day without losing vast amounts of body water through evaporative cooling, such as by sweating or panting.
Archaic mammals did not have scrotums, in which the testes are kept cool, and if there had not been a way to keep sperm cool, quality would have declined through the accumulation of free radicals with the increases in temperature during sperm maturation. By becoming active during the cooler nights, these mammals were able to preserve sperm quality. A nocturnal lifestyle could solve this problem, now that they were “warm-blooded,” with the newly acquired thermoregulatory toolkit to cope with the cooler night air.