difference between two given dates without using PHP date functions or objects
i need to calculate difference between two given dates without using PHP date functions or objects
here my first code but it dosn't work weel! Any idea/tips?
need to calculate difference between two given dates without using PHP date functions or objects
@ilmala Why? If you really need to do so, then just compare two UNIX timestamps:
$start = strtotime('1 October 2016');
$end = strtotime('31 October 2016');
return $end - $start; // Difference in seconds. Do what you want with it here.
Ok, here's my point of view: This is a stupid test. Use proper tools to do the job you're trying to do. Your instructor is the picture in the book next to the axiom "those who can't do, teach"
As for a tip -- it doesn't matter if your code doesn't work as to my eye you didn't accomplish the idiotic requirement of not using any php function or objects.
It's a test send me to get a job interview. My only question was if there is a different way to do this? because my code don't work well compared with php function. Is a stupid test ... yes!
@jlrdw I don't do other peoples homework. And the OP should use your answer! It is as always on point. And exactly @willvincent and if this is an interview question would you want to work there? Poor question asked by someone who should not be interviewing.
@ilmala use martinbean's suggestion.. strtotime, get absolute value of date1 - date2, then parse out number of years, months, days, etc. from that resulting number of seconds.
Most people though, would probably just use carbon. or something like this
Seriously though.. this is a bullshit question, whoever asked it -- as has been said here -- shouldn't be interviewing people.