When you want it to be over
A prohibition, then a way to phrase it that is allowed.
لاَ يَتَمَنَّيَنَّ أَحَدُكُمُ الْمَوْتَ مِنْ ضُرٍّ أَصَابَهُ، فَإِنْ كَانَ لاَ بُدَّ فَاعِلاً فَلْيَقُلِ اللَّهُمَّ أَحْيِنِي مَا كَانَتِ الْحَيَاةُ خَيْرًا لِي، وَتَوَفَّنِي إِذَا كَانَتِ الْوَفَاةُ خَيْرًا لِي
Allāhumma aḥyinī mā kānati-l-ḥayātu khayran lī, wa tawaffanī idhā kānati-l-wafātu khayran lī.
“O Allah, keep me alive as long as life is better for me, and take me when death is better for me.”
None of you should wish for death because of a hardship. If he must, let him say this instead.
The full narration
Narrated Anas bin Malik:The Prophet (ﷺ) said, "None of you should wish for death because of a calamity befalling him; but if he has to wish for death, he should say: "O Allah! Keep me alive as long as life is better for me, and let me die if death is better for me
Source
Ṣaḥīḥ al-Bukhārī · 5671
- Agreed upon as authentic (al-Bukhārī / Muslim)