Can't Convert string binary to long.

Hello everyone,

I have a problem, it might be a trivial problem though…

I need to save the last date and time when the user leaves the game or quits the game.
And get back when starts the game again, just to calculate the difference in time, since there are factors that will be decremented with respect to time.

void Start () 
{
    CalculateTimeDifference(); 
}
   
void OnApplicationPause(bool pauseStatus)
{
  paused = pauseStatus; // Check the state of the application
        		
   if(paused)
      PlayerPrefs.SetString("sDate",System.DateTime.Now.ToBinary().ToString());         						
        	
   if(!paused)					
        CalculateTimeDifference();		
}


void OnApplicationQuit()
{
    PlayerPrefs.SetString("sDate",System.DateTime.Now.ToBinary().ToString());
}


private void CalculateTimeDifference()
{
    currentDate = System.DateTime.Now;
    long temp = Convert.ToInt64(PlayerPrefs.GetString("sysString"));
    DateTime oldDate = DateTime.FromBinary(temp);
    TimeSpan difference = currentDate.Subtract(oldDate);
}

When CalculateTimeDifference() is called in the start function, it gives me ar error.
The errors says:

“FormatException: Input string was not in the correct format
System.Int64.Parse (System.String s)”

I can’t guess what might be wrong with this ?? any help please

You’re writing sDate but reading sysString.

OnApplicationPause was called everytime I start the game, and it is called before the Start function.

I added

if(!paused)		
{
   if(PlayerPrefs.HasKey("sysString"))
   {
	CalculateTimeDifference();	
   }
}

CalculateTimeDifference() function Gets from PlayerPrefs, while the first time or after (PlayerPrefs.DeleteAll), so there was no value (null) for PlayerPrefs.GetString(“sysString”), as mattssonon helped.
Adding PlayerPrefs.HasKey(“sysString”) will not call the function if no key, plus I removed the function call from the Start function.