Sequence alignment methods have the promise to reserve important temporal information in electronic health records (EHRs) for comparing patient medical records. Compared to global sequence alignment, local sequence alignment is more useful when comparing patient medical records. One commonly used local sequence alignment algorithm is Smith-Waterman algorithm (SWA), which is widely used for aligning biological sequence. However directly applying this algorithm to align patient medical records will obtain suboptimal performance since it fails to consider complex situations in EHRs such as the temporality of medical events. In this work, we propose a new algorithm called Knowledge-Enriched Local Sequence Alignment algorithm (KELSA), which incorporates meaningful medical knowledge during sequence alignments. We evaluate our algorithm by comparing it to SWA on synthetic EHR data where the reference alignments are known. Our results show that KELSA aligns better than SWA by inserting new daily events and identifying more similarities between patient medical records. Compared to SWA, KELSA is more suitable for locally comparing patient medical records.