How to check if a DateTime occurs today?

后端 未结 13 1273
故里飘歌
故里飘歌 2020-12-08 18:01

Is there a better .net way to check if a DateTime has occured \'today\' then the code below?

if ( newsStory.WhenAdded.Day == DateTime.Now.Day &&
             


        
13条回答
  •  长情又很酷
    2020-12-08 18:48

    As Guillame suggested in a comment, compare values of Date properties:

    newStory.Date == DateTime.Now.Date
    

提交回复
热议问题