Attending the sensory environment for cue detection is a cognitive operation that occurs on a time scale of seconds. The dorsal and ventral medial prefrontal cortex (mPFC) contribute to separate aspects of attentional processing. Pyramidal neurons in different parts of the mPFC are active during cognitive behavior, yet whether this activity is causally underlying attentional processing is not known. We aimed to determine the precise temporal requirements for activation of the mPFC subregions during the seconds prior to cue detection. To test this, we used optogenetic silencing of dorsal or ventral mPFC pyramidal neurons at defined time windows during a sustained attentional state. We find that the requirement of ventral mPFC pyramidal neuron activity is strictly time-locked to stimulus detection. Inhibiting the ventral mPFC 2 s before or during cue presentation reduces response accuracy and hampers behavioral inhibition. The requirement for dorsal mPFC activity on the other hand is temporally more loosely related to a preparatory attentional state, and short lapses in pyramidal neuron activity in dorsal mPFC do not affect performance. This only occurs when the dorsal mPFC is inhibited during the entire preparatory period. Together, our results reveal that a dissociable temporal recruitment of ventral and dorsal mPFC is required during attentional processing.