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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:06:29+00:00 2026-05-14T15:06:29+00:00

I know that when I use DateTime.Now.Ticks in C# it returns a long value

  • 0

I know that when I use DateTime.Now.Ticks in C# it returns a long value but I need to store it in an int variable and I am confused as to whether or not I can maintain that precision. As of right now I just have a cast

int timeStampValue = (int)DateTime.Now.Ticks;

This is a project constraint so I understand there is tons of precision lost. I guess I just couldn’t think of another way to do a timestamp thing stored in an int that I could then compare to other timestamps.

Any suggestions or advice on how to maintain the precision, if possible, would be much appreciated.

Everyone’s answers were illustrative. I actually ended up just setting up a process involving counters where when an item is used it’s counter is set to ‘0’ and all other counters are incremented by 1. Then whatever is the highest counter is the next item to use.

  • 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-14T15:06:29+00:00Added an answer on May 14, 2026 at 3:06 pm

    Do you need all the most-significant bits? (e.g. which year)

    Do you need all the least significant bits? (e.g. sub-nanosecond precision)

    How long an interval do you need to measure over?

    If you need millisecond precision only, why not lose the least significant bits

    int timeStamp = (int)(DateTime.Now.Ticks >> 10) // lose smallest 10 bits
    

    edit

    the OP wants to store times of recently used items: if this is user selections for a single user, you probably don’t want anything shorter than a second! as there are 10^7 ticks per second, there are log(10^7)/log(2)=23 excess bits in the long value!

    So how much space do you need? Well, your values ought to specify year, month, day, hour, minute and second; There are about 32 million seconds in a year = about 24 bits. add 3 bits if you want to store the last 10 years worth. So will easily fit into an int32.
    I’d suggest

    int timeStamp = (int)(DateTime.Now.Ticks >>23) // retain bits 23 to 55
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.