Could Matthew 12:40b and Matthew 17:23a be both true literally?
The answer I gave to the ... Q. How is it that Jesus could be "three days and three nights in the heart of the earth"? ... would seem to also have merit with regard to the Q. now posed, which is why I flagged it as being a 'duplicate' Q. just worded differently. The Q. was subsequently closed, albeit briefly, but then reopened during my 'leave of absence'. Whether I was right in my assumption of duplicity is by the way now. A brief answer to the present Q., IMO, is that there is no contradiction here between the two verses, as both are 'literally' true. For the record, I now reproduce the answer I gave to the former Q. as I obviously feel that it is also quite relevant here ....
How is it that Jesus could be "three days and three nights in the heart of the earth"?
The OP (albeit some time ago) wanted a simple answer to this question, however, after researching the evidence from the scriptures, with regard also to 'Bible Hub Commentaries' and those of many other commentators, including all of the afore going answers and comments, it is my considered opinion that there is no one simple answer. Theories abound. BUT, nowhere did I read the following hypothesis that I'm about to endeavor to lay out.
Matt 12:40 (as per the KJV)...For as Jonas was three days and three nights in the whale's belly; so shall the Son of Man be three days and three nights in the heart of the earth.
The general consensus of opinion, is that there is little doubt that Matthew, being in lockstep with Jewish tradition, was talking about 'parts' of days and not 24 hour, or even 12 hour days. The word 'day' here would appear to have been taken loosely. Nights, on the other hand, not so much. Most everyone (not all) are of the opinion that the scriptures, at the very least, allow for 'parts' of three days and two full nights. So, how does one fit a third night into the equation, without going against scripture?
Well, let's go to the scriptures!!
Notice that in Luke 24:7 (NASB) we have the following...saying that the Son of Man must be delivered into the hands of sinful men, and be crucified, and the third day rise again." See also Matt 16;21 & Luke 24:46.
I have taken the liberty of italicizing from delivered into... as up until the point of delivery Jesus was very much his own man, so to speak, but thereon after he was under arrest ( to all intents and purposes, a prisoner); suffered ridicule and torture; was subsequently crucified and died, but then on the third day rose up again. The comparison with Jonah IMO is unmistakable. From the moment the fish swallowed him, he was arrested in his tracks. In other words the three days and nights of Jonah's imprisonment inside the belly of the all encompassing fish started with the swallowing and ended with him rising up and out of same.
Jonah may not have died while imprisoned in the belly of the whale/fish, but for three days and three nights he felt like he was, increasingly, suffering in 'hell'. From late Thursday evening onwards, not long after Jesus, himself, instigated the first of two Passover meals, the Last Supper, Jesus' own hellish suffering commenced, until actual death overcame him on Friday, the day after the Last Supper, whereupon he then literally resided in 'Hell', continuing through the whole of Saturday, until he rose again early on the third day, Sunday, albeit before the daylight hours, which is not a problem when one considers that traditionally 'the day' started from sunset, the previous day.
The inclusion of Thursday night, in this hypothesis, ended up being a 'no brainer' to me, even though it's inclusion would seem to go against all other hypotheses. Jesus truly became lower than the angels (Heb 2:7), when the sinful men were able to arrest and subject him to torture and ridicule. His further descent ...into the lowest depths/into the heart of the earth...was in continuance from the Thursday night arrest.
So, now we have:
Thursday night (1st night, albeit partial) - Jesus' freedom curtailed (mirroring the swallowing of Jonah).
All day Friday (1st day) - Jesus crucified. Friday night (2nd night).
All day Saturday (2nd day) - The crux of 'in the heart of the earth'. Saturday night (3rd night).
Sunday, in the early morn' (3rd day) - Jesus is arisen.