Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Nov 24, 2018 at 06:01 PM by mustang4484 for the following reason:

Other

avatar image
1
Question by mustang4484 · Nov 04, 2018 at 07:29 PM · datetime

Day elapsed or day counter

hello everyone I would like to do a days count from the birth date "x" synchronized with the actual days that pass. The day of birth as an x = System.DateTime.Now; but I do not know how to compare the other days then to make sure that each time you increase one.

You can give me any tips?

Thank you

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

  • Sort: 
avatar image
0

Answer by toddisarockstar · Nov 05, 2018 at 05:35 AM

I needed to do the same awhile ago and didnt find any shortcuts. thought I would share what i came up with. it works good for getting days passed between dates. It doesn't include leap year so once every 4 years, if the two dates are before and after the last leap the comparison is off. but it would be easy to add the adjustment if it matters to you.

 public static int daysSince2000(string datetimestring){
         int ret = 0;
         string[] sa = datetimestring.Split ("/"[0]);
         int d, m, y;
         int.TryParse(sa [1],out d);
         int.TryParse ( sa [0],out m);
         int.TryParse (sa [2].Substring (2, 2),out y);
         while(y>0){y--;ret+=365;}
         while(m>0){m--;ret+=months[m];}
         while(d>0){d--;ret+=1;}
         return ret;
     }
 
 
     public static int[] months = new int[]{
         31,//jan
         28,//feb
         31,//mar
         30,//apr
         31,//may
         30,//jun
         31,//jul
         31,//aug
         30,//sep
         31,//oct
         30,//nov
         31,//dec
     }; 
 
 
     public void Start (){
 
         string now = System.DateTime.Now.ToString ();
         string FutureExample = "01/30/2019 11:19:01 PM"; 
 
         int count1 = daysSince2000 (now);
         int count2 = daysSince2000 (FutureExample);
 
         print ("days passed between dates= " + (count2 - count1));
      }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by mustang4484 · Nov 23, 2018 at 08:58 AM

ok thank you, and if i would like to read only the number of the day from string?

Example today is 23/11/2018 and i would read only the "23" from system.datetime.now?

Thank you!!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

94 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to compare two dates? 1 Answer

Saving System.DateTime in a Serialized Scriptable Object is defaulting 1 Answer

Convert datetime not working in android 0 Answers

Formatting Calendar, Iterating through list of strings. 1 Answer

Shortening a DateTime Variable 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges