8

Basically I need to display how much time till a specified time or if its passed, how much time since it passed.

The original string would look just like this: 07/20/2011 01:13 am

EDIT: switched from doing conversion in javascript to php:

//get local time in UTC format
echo gmdate("Y/m/d\TH:i:s\Z");
  echo '<br />';

 //convert time to UTC
  $the_date = strtotime("07/20/2011 01:13 am");
  echo date("Y/m/d\TH:i:s\Z",$the_date);

Doing the above gives me these to work with:

//local time
2011/07/20T19:49:39Z
//specified time
2011/07/20T01:13:00Z

How can I take the specified time, and the local time and make it display something like these examples:

Started 36 mins ago
Will start in 33 mins
Will start in 6 hrs 21 mins
Will start in 4 days 4 hrs 33 mins
brybam
  • 5,009
  • 12
  • 51
  • 93
  • I found a function that can be used to add or subtract minutes from a date, and it can easily be modified in order to add or subtract two dates: http://stackoverflow.com/questions/1197928/how-to-add-30-minutes-to-a-javascript-date-object/1214753#1214753 – Anderson Green Feb 25 '13 at 04:44

2 Answers2

6

And if you want to do it in Javascript, it is slightly more painful but you get the benefit of a "live" countdown.

Here's a great breakdown of how to do that.

http://ditio.net/2010/05/02/javascript-date-difference-calculation/

Edgar Velasquez Lim
  • 2,426
  • 18
  • 15
  • That's an interesting example. Unfortunately my javascript skills aren't all that great yet. I'm having trouble with the actual "conversion" of the utc, and i wouldnt know how to make it automatically switch from "Will start" to something like "Started 36 mins ago". Also that example doesn't demonstrate in min/days/hours – brybam Jul 20 '11 at 20:17
0

See the manual. The example #3 with the use of datediff will help you too.

childno͡.de
  • 4,679
  • 4
  • 31
  • 57