No such time as 12 am !!!! Do you mean 12 midnight or 12 noon???
'am' are the Latin initials for 'Ante Meridian' ; Before Noon.
If it is midnight or noon it is NOT before or after noon.
To answer your question, assuming you mean '12 midnight', then . from 5 pm to 12 midnight it is 7 hours.
NB If you mean 12 noon then from 5 pm to the following 12 noon , it is 19 hours.
Chat with our AI personalities