DragonPrime - LoGD Resource Community
Welcome Guest
  • Good morning, Guest.
    Please log in, or register.
  • September 02, 2010, 09:45:52 AM
Home Forums News Links Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
IRC Channels
Search

Pages: [1] 2   Go Down
  Print  
Author Topic: date/time help  (Read 1344 times)
0 Members and 1 Guest are viewing this topic.
sixf00t4
Mod God
*****
Offline Offline

Posts: 1916



View Profile WWW
« on: December 01, 2005, 07:26:26 PM »

help!
ok, have an entry in the db for the event start and I have a setting for how many days until the finish (could be either real days or game days, doesn't matter, which ever is easiest)  and i want to calculate 2 things.

1.  a pretty count down to the finish, in "next newday" format (X days, X hours, X seconds)

2.  determine if "now" > finish so that it can run the finish function.

all i have is an edit of reltime():
Code:
function timeleft($start,$end){
   $x = abs($end - $start);
   $d = (int)($x/86400);
   $x = $x % 86400;
   $h = (int)($x/3600);
   $x = $x % 3600;
   $m = (int)($x/60);
   $x = $x % 60;
   $s = (int)($x);
   if ($d > 0)
      $o = "$d day".($d>1?"s":"").($h>0?", $h hour".($h>1?"s":""):"");
   elseif ($h > 0)
      $o = "$h hour".($h>1?"s":"").($m>0?", $m minute".($m>1?"s":""):"");
   elseif ($m > 0)
      $o = "$m minute".($m>1?"s":"").($s>0?", $s second".($s>1?"s":""):"");
   else
      $o = $s." second".($s>0?"s":"");      
   return $o;
}

I tried tinkering with the time_to_interval() function given at php.net http://us3.php.net/strtotime  but i can't get it right.

and right now i'm using:
Code:
$start=date("Y-m-d h:m:s",strtotime($row['date']));
Code:
Logged

Dannic
Guest
« Reply #1 on: December 01, 2005, 08:18:23 PM »

Have you looked at how the garden party module works?  Maybe that will give you a small bit of insight.
Logged
sixf00t4
Mod God
*****
Offline Offline

Posts: 1916



View Profile WWW
« Reply #2 on: December 01, 2005, 09:06:14 PM »

hmm, it does indeed!  ...getting somewhere anyway...i just don't have the spacial reasoning for this!

$start= when it was created.
$finish = $start + length
$timeleft = ($finish-start)-($now-start)...right?
Logged

Catscradler
Codemeister
****
Offline Offline

Posts: 298


View Profile WWW
« Reply #3 on: December 01, 2005, 09:33:29 PM »

Almost.
$timeleft = $finish-$now
When you expand your formula, the two $starts cancel each other out.
Logged

Co-author of the in-game FAQ. Administrator on Classic Server.
sixf00t4
Mod God
*****
Offline Offline

Posts: 1916



View Profile WWW
« Reply #4 on: December 02, 2005, 01:11:20 AM »

heh, oh yeah:)  

now, just got to figure out how to get $finish.  Wink
Logged

XChrisX
Global Moderator
Mod God
*****
Offline Offline

Posts: 4647

Be aware of the squirrel!


View Profile WWW
« Reply #5 on: December 02, 2005, 01:13:49 AM »

$finish = $start + length

Here it is Smiley
Logged

Running for more than three years now:
sixf00t4
Mod God
*****
Offline Offline

Posts: 1916



View Profile WWW
« Reply #6 on: December 02, 2005, 01:18:28 AM »

I hope you're just being a jerk Grin
Logged

XChrisX
Global Moderator
Mod God
*****
Offline Offline

Posts: 4647

Be aware of the squirrel!


View Profile WWW
« Reply #7 on: December 02, 2005, 01:22:29 AM »

* XChrisX tries to look innocent...

No...

Code:
$length = 86400; // 1 day for example
$now = date("U");
$finish = $now + $length;

$finish is now a unix timestamp (of tomorrow)...

Code:
$finish = date("Y-m-d h:m:s", $finish);

Now it's a nice looking, cute date... Smiley
« Last Edit: December 02, 2005, 01:22:55 AM by XChrisX » Logged

Running for more than three years now:
sixf00t4
Mod God
*****
Offline Offline

Posts: 1916



View Profile WWW
« Reply #8 on: December 02, 2005, 02:13:57 AM »

$finish = $now + $length;

start + length, but I know what you meant...I *think* it's working.  I have to get the 2nd part working to be sure.

this should work, right?
Code:
 
    $end = strtotime("Y:m:d 00:00:00 O",get_module_setting("length"));
  $sql="select * from ".db_prefix("blahblah")." where date<date+$end";
Logged

XChrisX
Global Moderator
Mod God
*****
Offline Offline

Posts: 4647

Be aware of the squirrel!


View Profile WWW
« Reply #9 on: December 02, 2005, 02:18:05 AM »

personnaly, i simply wouldn't use real dates... Just use timestamps... And then compare these numbers against each other...

It's less confusing...
Logged

Running for more than three years now:
sixf00t4
Mod God
*****
Offline Offline

Posts: 1916



View Profile WWW
« Reply #10 on: December 02, 2005, 02:52:01 AM »

ok, let me change the inserts around to use U time instead....

while i'm doing that, seems like there is some weird effect due to the setting.

Code:
"length"=>"How many real days does this last?,datelength|5 days",

the time left is not adjusting right from the setting.  here's how i calc the time left.:
Code:
           $start=date("U",strtotime($row['date']));
         $length = strtotime("U",get_module_setting("length"));
         $now = date("U");
            $finish = $start + $length;         
         $timeleft=timeleft($now,$finish);
Logged

XChrisX
Global Moderator
Mod God
*****
Offline Offline

Posts: 4647

Be aware of the squirrel!


View Profile WWW
« Reply #11 on: December 02, 2005, 02:58:54 AM »

Seems to be okay...
Logged

Running for more than three years now:
SaucyWench
Mod God
*****
Offline Offline

Posts: 2238


I'm a good girl.


View Profile WWW
« Reply #12 on: December 02, 2005, 03:32:29 AM »

Date math is evil... there are three other instances I know of. One is the caravan... that code was Kendaer's and is long and convoluted to understand (I meant to redo that one, and you never know, I might one day).

The second is Talisman and Robert's Christmas Stocking...
And the easiest imo is my tourneylock (in user folder) that I only managed to do after staring at the Christmas Stocking and php.net for a bajillion hours.

These might help you.
Logged

SaucyWench
Owner of GemDust.com and Darton City proudly hosted by LunarPages
XChrisX
Global Moderator
Mod God
*****
Offline Offline

Posts: 4647

Be aware of the squirrel!


View Profile WWW
« Reply #13 on: December 02, 2005, 03:34:49 AM »

Date math is evil...
Date math is waiting behind THAT door... Grin

No, it's really the worst you can do to someone... That's why I'd always prefer timestamps... You can treat them almost like normal integers... Smiley
Logged

Running for more than three years now:
sixf00t4
Mod God
*****
Offline Offline

Posts: 1916



View Profile WWW
« Reply #14 on: December 02, 2005, 04:14:25 AM »

bah, no worky jerky...works busy today too, can't focus like i need to...

Logged

Pages: [1] 2   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Please take the time to read the FAQ and browse the DragonPedia

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Who's Online
30 Guests, 0 Users
DragonPrime LoGD
Recent Topics
Home Forums News Links Downloads Login Register Advanced Search