0

I create a game in unity. And I add a 'buy subscribe' (apple).

After click buy, I get Date (for example: 08/02/2018 07:24:23) 08 - is month, 02 - is date.

I get a date through this code: productReceipt.subscriptionExpirationDate

Now i need to do a check, if CurrentDay - 08/02/2018 07:24:23 = 15 days;

How to calculate 2 dates?

  • 1
    Covert string to datetime and caculate . https://stackoverflow.com/questions/919244/converting-a-string-to-datetime – siusiulala Aug 02 '18 at 07:37

1 Answers1

0

You can do it using DateTime function. DateTime function allows you to calculate the number of days. You just need to get current datetime & parse your string to datetime format. Here is the code.

DateTime dateCurrent = DateTime.Now;
DateTime dateNext = DateTime.Parse(date);
int days = (dateNext - dateCurrent).Days;

Update: You can also use TotalDays function to give the remaining time in fraction also. TotalDays is double so remember to change the days to double when using it.

Community
  • 1
  • 1
killer_mech
  • 1,568
  • 13
  • 26