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 Jan 05, 2017 at 10:17 PM by Hellium for the following reason:

This is not a Unity question but a pure C# related one, and thus, does not belong to Unity Answers.

avatar image
0
Question by KnightRiderGuy · Jan 05, 2017 at 09:56 PM · c#error messagestringinterrormessage

error CS0019: Operator `-' cannot be applied to operands of type `System.DateTime' and `string'

What the heck does this mean:

error CS0019: Operator -' cannot be applied to operands of type System.DateTime' and `string'

I'm trying to use it like this:

 public static string GetDaysPassedQ01()
     {
         LoadInformation.LoadStartDateQ01 ();
         Debug.Log(StartDateQ01);
         today = System.DateTime.Now;
 
         System.DateTime compareDate = today;    //.AddDays(0);
 
         System.TimeSpan difference;
 
         difference = compareDate - today;
         difference = compareDate - StartDateQ01;
         //difference = today - startDate;
         Debug.Log("Days Passed: " + difference.Days);
 
         return difference.Days.ToString();
     }

NOTE: The Debug.Log(StartDateQ01); shows this:

01/05/2017 14:04:48 UnityEngine.Debug:Log(Object)

Comment
Add comment · Show 1
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 dpoly · Jan 05, 2017 at 11:27 PM 0
Share

You need to convert StartDateQ01 from string to DateTime.

1 Reply

  • Sort: 
avatar image
0

Answer by Creeper_Math · Jan 05, 2017 at 10:13 PM

      difference = compareDate - today;
      difference = compareDate - StartDateQ01;

That's where the error is going on.. "today" and / or "StartDataQ01" is being stored in a string, so what the computer thinks your doing is taking a number and subtracting some text from it, which isn't possible....

My suggestion is to make sure that they all are being stored in the same variable way, and if you want to subtract them, you will have to turn them into System.DateTime (if you can use operators with those)...

What I would do (which is most likely the least energy efficient way) is to convert both bools into numbers 1 - 366 * year , and then after subtracting what I need, I would just convert them to the regular form... Which itself would take some extensive coding

Comment
Add comment · Show 1 · 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 KnightRiderGuy · Jan 05, 2017 at 10:22 PM 0
Share

ell in my save script I'm doing this:

 public static void SaveStartDateQ01(){
         UserInformation.startDate = System.DateTime.Now ; //save the start date ->
         PlayerPrefs.SetString ("DateAsked", UserInformation.StartDateQ01);
         Debug.Log("Saving The Date You Asked This $$anonymous$$ichael " + (System.DateTime.Now));
     }

And in my load script i'm doing this:

 public static void LoadStartDateQ01(){
         UserInformation.StartDateQ01 = PlayerPrefs.GetString ("DateAsked");
         Debug.Log("You Asked $$anonymous$$e This Question On This Date $$anonymous$$ichael " + PlayerPrefs.GetString ("DateAsked"));
     }

All I really need is to uses this information in an if statement to check how many days has passed. something like if (daysPassed <= 1){

Do something

Follow this Question

Answers Answers and Comments

265 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 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 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

Distribute terrain in zones 3 Answers

How to Call a Number Using WWW and Actually Do Something With The Number (Please Read) 1 Answer

GetHashCode() questions/Turning a text string into an int 1 Answer

Can I create a list with an int/float and a string? C# 2 Answers

Changing a GUI String to read as a INT 2 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