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

  • SEARCH
  • Home
  • 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 7534231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:57:28+00:00 2026-05-30T05:57:28+00:00

I want to compare between two dates. From both the dates, I am fetching

  • 0

I want to compare between two dates.
From both the dates, I am fetching only date component using ToShortDateString(), as shown below. Now the problem is when I’m comparing the two dates. Its throwing error —

“Operator >= can’t be applied to operands of type string and string.”

DateTime srtdate = Convert.ToDateTime(allitem["StartDate"].Text.ToString());
DateTime srtdate = Convert.ToDateTime(allitem["StartDate"].Text.ToString());

 (DateTime.Now.ToShortDateString() >= srtdate.ToShortDateString()) 

I need to compare date component only, NOT date and time together.

Please suggest what is the alternative way. Thanks

To JON:-

(I went tyhrough all what you explained and understood hopefully what the point actually you trying to make. Just to clarify more and make a last check I ll show an example.)
I have an web interface, where I give a start date and end date for a XYZ name (Note I can enter only date here, not time).

Start Date – 22-Feb-2012 AND End Date – 22-Feb-2012

Now in back end (code), if Start date and End date is same as Current date OR current date is in between start and end date, I want a ACTIVE flag set or else not. I give the condition as this:-

if ((DateTime.Today >= strdate.Date) && (DateTime.Today <= enddate.Date))
                    lblCondition.Text = "CHECKED";

Now when I debug the code,

Both DateTime.Today and strdate.Date gives the value as 2/22/2012 12:00:00 AM.

So, Jon my question is:- Would ‘today’ and ‘date’ work as per mentioned requirement, where only date component used. I hope it would.

Thanks a lot for all your explanantion before.

  • 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-30T05:57:29+00:00Added an answer on May 30, 2026 at 5:57 am

    Why are you converting to a string representation at all? If you only want to compare the date parts to two DateTime values, just use the Date property on each of them:

    if (x.Date >= y.Date)
    

    And the Today property is equivalent to DateTime.Now.Date.

    Both Date and Today strip off the time part, leaving a time of midnight. It’s not ideal that you’ve still got a type which is capable of representing times, but that’s just the way the DateTime API works 🙁

    Note that you should usually avoid using DateTime.Now or DateTime.Today in web applications unless you’re really comfortable with it using the system default time zone as the day boundary. The user’s idea of “today” may not be the same as the server’s.

    You should avoid using string conversions unless your goal is really to get a text representation.

    Of course another alternative would be to use the date/time library I’m building, Noda Time, where you could use a LocalDate type – obviously that makes it clearer that you’re only interested in the date and not the time.

    EDIT: As the OP seems unconvinced that Date really does ignore the time component, here’s an example:

    using System;
    
    public class Test
    {
        static void Main()
        {
            // Two DateTime values with different times but
            // on the same date
            DateTime early = new DateTime(2012, 2, 22, 6, 0, 0);
            DateTime late = new DateTime(2012, 2, 22, 18, 0, 0);
    
            Console.WriteLine(early == late); // False
            Console.WriteLine(early.Date == late.Date); // True
        }    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using SQL Server 2000 I want to compare the table2.date between table1.from, table1.todate, if
I want to compare(finding remaining days and time between two days) using joda time.
I want to find time difference between two date and then compare the difference
I want to compare two arrays, one coming from a shoppingcart and the other
Using VB6 I want to compare the system date, if the exe should not
i want to compare between two times the first one is getting by the
I want to compare two NSDates with NOW ([NSDate date]). NSDate *date1 = [NSDate
Possible Duplicate: How to find number of days between two dates using php I'm
I want to calculate the difference between two times and then compare difference is
I've got two tables, and I want to compare the data between them, and

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.