How can I calculate how many nights are there in a date range?

前端 未结 1 1860
Happy的楠姐
Happy的楠姐 2021-01-12 15:34

I need to calculate the quantity of nights (stay at a hotel) from the checkin and checkout dates.

What is the best way to do it?

ie: If I have



        
相关标签:
1条回答
  • 2021-01-12 16:27

    DateTime has a property that returns the Date part which is the DateTime in midnight. You can use this part to get the nights since all parts of day will be mapped to the same time at day:

    (Checkout.Date - Checkin.Date).Days
    
    0 讨论(0)
提交回复
热议问题