4
First of all, I’ve done a lot of research here on the site and I haven’t found any more in-depth examples, just basic questions/answers on how to get the difference between dates, what I was able to do and it works as I wish.
However, the code that I currently possess, seems to me a little "heavy" but as I do not have advanced knowledge in PHP, I do not know how could simplify.
I have a JSON file with some data, some of it needs to be updated when it is already 30 minutes since its creation. For this I use the following code to create the time used in the json file:
'time' => date('m/d/Y H:i:s')
When I do the date request, I then compare the date saved in the json file with the current date. If it is more than 30minutes, I have to do another treatment. This is the code I currently use:
$fileTime = new DateTime($file['time']); //Data obtida do arquivo json
$currTime = new DateTime();
$interval = date_diff($fileTime, $currTime);
if($interval->y >= 1 || $interval->m >= 1 || $interval->d >= 1 || $interval->h >= 1 || $interval->i >= 30) {
//Chama função
}
The problem with that is that if it’s 1:10 minutes and I just check the minutes, it’s going to give a wrong result, since it’s been over 30 minutes, so I have to check every house after the minute too.
Is there any way to simplify this verification?
Baco, I’m having a doubt, I’m doing with the following dates: $date1 = strtotime( '10/04/2016 15:00' ); $date2 = strtotime( '11/04/2016 18:10' ); and it’s showing me a difference of 747 hours, as is possible?
– Gonçalo
"When the date is separated by dashes, PHP already interprets as DD-MM-YYYY, and with bars as MM/DD/YYYY"
– Bacco
In other words, if this 11 is to be the day, use the format "11-04-2016". If you use bar, it is in the American standard
– Bacco
And as I would with bars, to change the form to day-month-year?
– Gonçalo
Only switch to dash when calling strftime
– Bacco
Thank you, Bacco!
– Gonçalo
@Gonçalo http://ideone.com/UK1RYg - and here is the solution to use today and show in minute and second hour: http://answall.com/questions/156717/70
– Bacco
Thank you Bacco! I will see everything you sent me.
– Gonçalo