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 9221301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:32:58+00:00 2026-06-18T03:32:58+00:00

I’m trying to compare 2 datetimes in asp.net but its ignoring the millisecond part.

  • 0

I’m trying to compare 2 datetimes in asp.net but its ignoring the millisecond part.

I tried use linq:

messages.OrderBy(x => x.Date);

and also tried

messages.OrderBy(x => x.Date).ThenBy(x=>x.Date.Millisecond);

and also using sort

messages.Sort((x, y) => DateTime.Compare(x.Date, y.Date));

and tried convert the datetime with string format but its also ignoring the milliseconds.

The datetime field in the object is bringing the datetime with the milliseconds correctly.
I’m using Asp.net MVC3 with databases Informix, Oracle and SQL Server.

  • 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-06-18T03:33:00+00:00Added an answer on June 18, 2026 at 3:33 am

    You’ve made a mistake somewhere, a DateTime is stored internally as a number

    Time values are measured in 100-nanosecond units called ticks, and a particular date is the number of ticks since 12:00 midnight, January 1, 0001 A.D. (C.E.) in the GregorianCalendar calendar
    (source)

    When you sort using a DateTime, it is simply doing an integer sort using this underlying value. Therefore if your DateTime instance has information about the number of milliseconds, it will be included in the sort. This can be demonstrated using code such as:

    var dates = new[]{
        new DateTime(2013,1,31,12,0,0,10),
            new DateTime(2013,1,31,12,0,0,20),
            new DateTime(2013,1,31,12,0,0,5)
    };
    
    foreach(var date in dates)
    {
        Console.WriteLine("{0:yyyy-MM-dd HH:mm:ss.fff}", date);
    }
    
    Console.WriteLine("-------------");
    
    foreach(var date in dates.OrderBy(dt => dt))
    {
        Console.WriteLine("{0:yyyy-MM-dd HH:mm:ss.fff}", date);
    }
    

    Which gives the output:

    2013-01-31 12:00:00.010
    2013-01-31 12:00:00.020
    2013-01-31 12:00:00.005
    -------------
    2013-01-31 12:00:00.005
    2013-01-31 12:00:00.010
    2013-01-31 12:00:00.020
    

    Clearly demonstrating that sorting a list of datetimes correctly places the earlier number of milliseconds first.

    Try it for yourself: http://rextester.com/HYQIM13679

    As to why this isnt happening for you, thats impossible to answer as you’ve not supplied details of how you come by your list of objects containing a field with a DateTime which you are sorting on. One possibility is that your source data is actually a string and you are using some variant of DateTime.Parse / DateTime.ParseExact and have forgotton to specify that you wish to capture the millisecond part so they are being set to zero for every instance.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am confused How to use looping for Json response Array in another Array.

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.