1

I have a problem with my script and I dont understand where is the problem. So I have this code :

 $i_now = strtotime(date('Y-m-d'));
 $i_date_last_bonus = strtotime($o_member->date_last_bonus);                
 $i_datediff = round(abs($i_now - $i_date_last_bonus) / 86400);
 print_r("Date Now :".date('Y-m-d'));
 print_r("Last Win :".$o_member->date_last_bonus);

I get the $i_datediff = 1 and I dont understand why because in the print_r I have Date Now :2015-12-04 and Last Win:2015-12-03 Can you help me please where I make the error ? Thx in advance and sorry for my english

Harea Costicla
  • 797
  • 3
  • 9
  • 20

2 Answers2

2

In one day there are 24 Hrs, in each hour there are 60Min, in each min there are 60sec. Hence, there are 24*60*60 = 86400sec in one day.

Now, The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Means it returns seconds.

so, i_now = 1449187200 andi_date_last_bonus = 1449100800 Difference is 86400sec.

Now $i_datediff = round(abs($i_now - $i_date_last_bonus) / 86400); this is converting seconds in days.

And Difference is 86400 / 86400 = 1 means 1 day.

AkshayP
  • 2,141
  • 2
  • 18
  • 27
1

This result is correct as you get the number of seconds between two dates first and then you divide it by the number of seconds in 24 hours (86400) which gives you 1 (day) as a result.

onerror
  • 606
  • 5
  • 20