~Matt~ Posted August 29, 2009 Share Posted August 29, 2009 I think I may have the solution to my other post:https://www.neowin.net/forum/index.php?showtopic=817650&view=getnewpost I will like calculate the difference between two dates in seconds through php. But I need someone to make a javascript function to convert a number of seconds to: Days hours:minutes:seconds Link to comment Share on other sites More sharing options...
0 XerXis Posted August 29, 2009 Share Posted August 29, 2009 sigh ;-) it's really not difficult, just some math function secondsToString(seconds) { var numdays = Math.floor(seconds / 86400); var numhours = Math.floor((seconds % 86400) / 3600); var numminutes = Math.floor(((seconds % 86400) % 3600) / 60); var numseconds = ((seconds % 86400) % 3600) % 60; return numdays + " days " + numhours + " hours " + numminutes + " minutes " + numseconds + " seconds"; } take it from there Link to comment Share on other sites More sharing options...
0 ~Matt~ Posted August 29, 2009 Author Share Posted August 29, 2009 lol, sorry for the trouble :) Thanks a lot!!! works like a charm!!! Link to comment Share on other sites More sharing options...
0 XerXis Posted August 29, 2009 Share Posted August 29, 2009 lol, sorry for the trouble :) Thanks a lot!!! works like a charm!!! np Link to comment Share on other sites More sharing options...
0 thiXkull Posted August 29, 2009 Share Posted August 29, 2009 why would u wanna use js when u need php? Try this for finding the difference in days between 2 dates/datetimes... take note though, date_parse requires PHP version 5.1.3 or higher. <?php /** * Finds the difference in days between two calendar dates. * * @param Date $startDate * @param Date $endDate * @return Int */ function dateDiff($startDate, $endDate) { // Parse dates for conversion $startArry = date_parse($startDate); $endArry = date_parse($endDate); // Convert dates to Julian Days $start_date = gregoriantojd($startArry["month"], $startArry["day"], $startArry["year"]); $end_date = gregoriantojd($endArry["month"], $endArry["day"], $endArry["year"]); // Return difference return round(($end_date - $start_date), 0); } ?> Link to comment Share on other sites More sharing options...
0 XerXis Posted August 29, 2009 Share Posted August 29, 2009 why would u wanna use js when u need php?Try this for finding the difference in days between 2 dates/datetimes... take note though, date_parse requires PHP version 5.1.3 or higher. <?php /** * Finds the difference in days between two calendar dates. * * @param Date $startDate * @param Date $endDate * @return Int */ function dateDiff($startDate, $endDate) { // Parse dates for conversion $startArry = date_parse($startDate); $endArry = date_parse($endDate); // Convert dates to Julian Days $start_date = gregoriantojd($startArry["month"], $startArry["day"], $startArry["year"]); $end_date = gregoriantojd($endArry["month"], $endArry["day"], $endArry["year"]); // Return difference return round(($end_date - $start_date), 0); } ?> because he want's a countdown counter which would be stupid to do in php? Link to comment Share on other sites More sharing options...
0 thiXkull Posted August 29, 2009 Share Posted August 29, 2009 http://andrewu.co.uk/clj/countdown/ that should help you. its very simple to implement. Link to comment Share on other sites More sharing options...
Question
~Matt~
I think I may have the solution to my other post:https://www.neowin.net/forum/index.php?showtopic=817650&view=getnewpost
I will like calculate the difference between two dates in seconds through php.
But I need someone to make a javascript function to convert a number of seconds to: Days hours:minutes:seconds
Link to comment
Share on other sites
6 answers to this question
Recommended Posts