Countup from a Date


/ Published in: PHP
Save to your folder(s)

I've been using a Javascript to do the same thing for years but have always wanted to do the same thing in PHP -- just never got around to writing it. Fortunately, ScriptyGoddess did it for me. Haven't actually implemented it but it looks like it should work.


Copy this code and paste it in your HTML
  1. <?
  2. // enter start date below like this: "January 2, 2001"
  3. $start = "January 29, 2002";
  4. // enter string of what this start date is.
  5. $text = "have passed since I had a fulltime job.";
  6.  
  7. //--------------------------
  8. $now = strtotime ("now");
  9. $then = strtotime ("$start");
  10. $difference = $now - $then ;
  11. $num = $difference/86400;
  12. $days = intval($num);
  13. $num2 = ($num - $days)*24;
  14. $hours = intval($num2);
  15. $num3 = ($num2 - $hours)*60;
  16. $mins = intval($num3);
  17. $num4 = ($num3 - $mins)*60;
  18. $secs = intval($num4);
  19. ?>
  20.  
  21. <p>
  22. <? echo $days ?> days,
  23. <? echo $hours ?> hours,
  24. <? echo $mins ?> minutes,
  25. <? echo $secs ?> seconds
  26. <? echo $text ?>
  27. </p>

URL: http://www.scriptygoddess.com/archives/2002/05/23/count-up-timer-in-php/

Report this snippet


Comments


You need to login to view comments.