Results 1 to 7 of 7

Thread: Compare two Dates.

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Compare two Dates.

    hi guyz! Currently, i have the code below
    Code:
                    if (dtpDate.Value.ToShortDateString != DateTime.Now.ToShortDateString)
                    {
                       result = MessageBox.Show(this,"The date is not the date today.", "BCMD", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                       MessageBox.Show(this, result.ToString ());
                    }
    but when try to run it it gives me an error saying "Operator '!=' cannot be applied to operands of type 'method group' and 'method group'". Can anybody please tell me what is the right way to compare two dates? thanks in advance!!!

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Compare two Dates.

    Why not just use DateTime.Compare() method to compare the dates?
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Compare two Dates.

    Yes, because what you're doing currently is comparing object methods. You need to add the argument list parentheses () to actually call the method and use its return value.

    Note that you don't need to call that method at all, if all you want to do is compare the date values.

  5. #5

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Compare two Dates.

    Thanks a lot bros!!!

  6. #6

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Compare two Dates.

    Mabalos popskie!!!

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Compare two Dates.

    Unless you have any further questions please go to the "Thread Tools" menu above the first post and click "Mark Thread Resolved". This will let other forum users know your question has been answered. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width