Php returns the relative time (such as: 20 minutes ago, 3 days ago) method, php days ago
This example describes how php returns relative time (for example, 20 minutes ago, 3 days ago. Share it with you for your reference. The details are as follows:
Function plural ($ num) {if ($ num! = 1) return "s";} function getRelativeTime ($ date) {$ diff = time ()-strtotime ($ date); if ($ diff <60) return $ diff. "seconds ". plural ($ diff ). "before"; $ diff = round ($ diff/60); if ($ diff <60) return $ diff. "Minute ". plural ($ diff ). "before"; $ diff = round ($ diff/60); if ($ diff <24) return $ diff. "Hour ". plural ($ diff ). "before"; $ diff = round ($ diff/24); if ($ diff <7) return $ diff. "Day ". plural ($ diff ). "before"; $ diff = round ($ diff/7); if ($ diff <4) return $ diff. "Week ". plural ($ diff ). "before"; return "on ". date ("F j, Y", strtotime ($ date ));}
I hope this article will help you with php programming.