كتاب الأيمان
27  
The Book of Oaths
(3)
Chapter: It is recommended for the one who swears an oath then sees that something else is better than it; To do that which is better and offer expiation for his oath
(3)
باب نَدْبِ مَنْ حَلَفَ يَمِينًا فَرَأَى غَيْرَهَا خَيْرًا مِنْهَا أَنْ يَأْتِيَ الَّذِي هُوَ خَيْرٌ وَيُكَفِّرَ عَنْ يَمِينِهِ
Sahih Muslim 1650 a

Abu Huraira reported:

A person sat late in the night with Allah's Apostle (ﷺ), and then came to his family and found that his children had gone to sleep. His wife brought food for him. but he took an oath that he would not eat because of his children (having gone to sleep without food) He then gave precedence (of breaking the vow and then expiating it) and ate the food He then came to Allah s Messenger (ﷺ) and made mention of that to him, whereupon Allah's Messenger (may peace he upon him) said: He who took an oath and (later on) found something better than that should do that, and expiate for (breaking) his vow.
حَدَّثَنِي زُهَيْرُ بْنُ حَرْبٍ، حَدَّثَنَا مَرْوَانُ بْنُ مُعَاوِيَةَ الْفَزَارِيُّ، أَخْبَرَنَا يَزِيدُ بْنُ كَيْسَانَ، عَنْ أَبِي حَازِمٍ، عَنْ أَبِي هُرَيْرَةَ، قَالَ أَعْتَمَ رَجُلٌ عِنْدَ النَّبِيِّ صلى الله عليه وسلم ثُمَّ رَجَعَ إِلَى أَهْلِهِ فَوَجَدَ الصِّبْيَةَ قَدْ نَامُوا فَأَتَاهُ أَهْلُهُ بِطَعَامِهِ فَحَلَفَ لاَ يَأْكُلُ مِنْ أَجْلِ صِبْيَتِهِ ثُمَّ بَدَا لَهُ فَأَكَلَ فَأَتَى رَسُولَ اللَّهِ صلى الله عليه وسلم فَذَكَرَ ذَلِكَ لَهُ فَقَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏ "‏ مَنْ حَلَفَ عَلَى يَمِينٍ فَرَأَى غَيْرَهَا خَيْرًا مِنْهَا فَلْيَأْتِهَا وَلْيُكَفِّرْ عَنْ يَمِينِهِ ‏"‏ ‏.‏
Reference : Sahih Muslim 1650a
In-book reference : Book 27, Hadith 18
USC-MSA web (English) reference : Book 15, Hadith 4052
  (deprecated numbering scheme)