shift DateTime to beginning or ending of the day

Posted on 2006-04-26
Last Modified: 2011-10-03
I have a call i am making in a property set:

if(value > this.datePicker.MaxDate)

9 times out of ten, this works fine, however, occasionaly the MaxDate has slightly fewer ticks than the value.  

i want to totally disregard the time component of the DateTime ( though i need these objects to remain as DateTimes).  

ultimatley, i just want to make sure value is on the same day or before max date.

if I call (date)value > (date)this.datePicker.MaxDate, will that work?  If I call subtract, will that work correctly?
Question by:jjacksn
    1 Comment
    LVL 12

    Accepted Solution


     you have Date property of DateTime struct which excludes the Time part:

      if (value.Date > DateTime.MaxValue.Date) ...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it. The first step, was to retrieve the image from camera into Image object. So that it can be displayed or …
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now