- Home /
I want to compare 2 dates but its not working!
On close I run this: PlayerPrefs.SetString("PlayDate", System.DateTime.Now.ToBinary().ToString());
On start I run this: long temp = Convert.ToInt64(PlayerPrefs.GetString("PlayDate")); DateTime oldDate = DateTime.FromBinary(temp);
I get this: FormatException: Input string was not in the correct format System.Int64.Parse (System.String s)
If I try this on close: currentDate = System.DateTime.Now; long date_bin = currentDate.ToBinary(); PlayerPrefs.SetString("PlayDate", date_bin.ToString());
and try this on open: long oldDate = long.Parse(PlayerPrefs.GetString("PlayDate")); DateTime oldDate = DateTime.FromBinary(oldDate);
I get this: FormatException: Input string was not in the correct format System.Int64.Parse (System.String s)
How do I Save the date and time someone starts playing. If they start playing again 23 hours later or while still playing and the 23 hour passes, add 10 to an int variable.
Anything I try doesn't work, says the system can't convert binary to long because the string isn't in the right format. It was working at some point, but its not working anymore for no reason.... I changed nothing, and now the string is not being stored into PlayerPrefs properly?
I don't care how the time is stored to PlayerPrefs as long as I can get it back out to compare the time with another using TimeSpan difference = currentDate.Subtract(oldDate);
all i'm trying to figure out is if 1 time is >=23 hours of another time retrieved from PlayerPrefs...
Answer by Opaapo56 · Dec 22, 2017 at 11:44 PM
@kevin5141 compare DateTime.Ticks instead https://msdn.microsoft.com/en-us/library/system.datetime.ticks(v=vs.110).aspx
Your answer

Follow this Question
Related Questions
Asset Server can't find P4Merge 2 Answers
comparing two materials 0 Answers
Greater than or equal to Vector3 1 Answer