Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6974543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:15:05+00:00 2026-05-27T17:15:05+00:00

I want to compare two dates. In pseudo-code: If the dueDate > now or

  • 0

I want to compare two dates. In pseudo-code:

If the dueDate > now or dueDate = now 

Then Fine Amount = something.

Else Fine Amount = 0

I wrote below code:

DateTime dueDate = Convert.ToDateTime(Reader1[3].ToString());
DateTime now = DateTime.Now;
int result = DateTime.Compare(dueDate, now);
if ((result < 0) || (result == 1))
{
    row["Fine_Amount"] = Convert.ToDouble(Reader1[4].ToString()); 
}
else
{
    row["Fine_Amount"] = 0;
}

This code gives wrong value, when

dueDate = 23-12-2011 AM 12:00:00
now = 23-12-2011 PM 05:26:54

I want to Compare:

dueDate = 23-12-2011
now = 23-12-2011

How do I remove the time in that?.

Adding below code is given result. But its to lengthy code.: –

 DateTime dueDate = Convert.ToDateTime(Reader1[3].ToString());
                    DateTime now = DateTime.Now;

                    if (dueDate.Year < now.Year)
                    {
                        row["Fine_Amount"] = Convert.ToDouble(Reader1[4].ToString());
                    }
                    else if (dueDate.Year > now.Year)
                    {
                        row["Fine_Amount"] = 0;
                    }
                    else if (dueDate.Year == now.Year)
                    {
                        if (dueDate.Month < now.Month)
                        {
                             row["Fine_Amount"] = Convert.ToDouble(Reader1[4].ToString();
                        }
                        else if(dueDate.Month > now.Month)
                        {
                             row["Fine_Amount"] = 0;
                        }
                        else if(dueDate.Month == now.Month)
                        {
                             if(dueDate.Day < now.Day)
                             {
                                 row["Fine_Amount"] = Convert.ToDouble(Reader1[4].ToString();
                             }
                             else
                             {
                                 row["Fine_Amount"] = 0;
                             }
                        }
                    }

Is there any way to short this code?.

Answer For this Question is

if (dueDate.Date >= now.Date)
{
    row["Fine_Amount"] = 0;
}
else
{
    row["Fine_Amount"] = Convert.ToDouble(Reader1[4].ToString());
}

This datetime.date is gives

 dueDate = 23-12-2011 AM 12:00:00 to 23-12-2011 AM 12:00:00 
    now = 23-12-2011 PM 05:26:54 to 23-12-2011 AM 12:00:00 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:15:05+00:00Added an answer on May 27, 2026 at 5:15 pm

    You can use DateTime.Now.Date

    According to docs, Date property returns: A new object with the same date as this instance, and the time value set to 12:00:00 midnight (00:00:00).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a notification system. Shortly.. to compare two dates, the only
I want to compare two NSDates with NOW ([NSDate date]). NSDate *date1 = [NSDate
I want to compare between two dates. From both the dates, I am fetching
How do I compare two dates in Lingo? To be specific, I want to
I want to compare two dates with time, I want all the results from
Possible Duplicates: Comparing dates How to compare two dates in Objective-C i want to
I have two lists with data that I want to compare dates for. I
I want compare two dates one would be the current date and other date
I've got two Dates and I want to compare them. I've logged the actual
I'm trying to compare two dates together and I only want to compare the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.