Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Using date/time's pre 1970-01-01... ?
Old 08-03-2008, 10:12 PM Using date/time's pre 1970-01-01... ?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Hello all,

Okay i am making a kbs/bandwidth calculator, and the way i have it its a fairly simple script and basically i want to use something like the date() function to allow me to display the out put in days/hours/seconds but of course the date is less than 1970-01-01 so its basically adding 1970-01-01 to the date which is annouying! ><

I came across the adodb functions which seem good but are not installed on myserver http://phplens.com/phpeverywhere/adodb_date_library i am looking into getting them installed but i doubt it will be possible so i need a work arround.

Note if you were wondering its being used with in a Smarty Template system (WHMCS) hence the weird code...

PHP Code:
$kbs $_POST['kbs']; //KB/s of the feed.
$bandwidth $_POST['bandwidth'];

$kb_bandwidth = ($bandwidth*1024)*1024//Total KBS / Month
$total_s $kb_bandwidth/$kbs;
$total_mim$total_s/60;
$total_hr$total_mim/60;
$total_day=$total_hr/24;
 
$total adodb_date('Y-m-d H:i:s'$total_s);

$smartyvalues["total_hr"] = $total
$smartyvalues["kbs"] = $kbs
Thanks and of course TP to anyone with a working answer!

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 08-04-2008, 01:37 AM Re: Using date/time's pre 1970-01-01... ?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Could you be more specific about what you're doing? An example would be great. I'm asking b/c I'm wondering why kb/s has anything to do with dates before 1970.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 08-04-2008, 02:44 AM Re: Using date/time's pre 1970-01-01... ?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Simply do the math.
You need to pile up the seconds, and once you've got the total seconds, divide them to get months, weeks, days and hours.

I did this, some years ago (man, I do love subversion, when you have to find old code...)
PHP Code:
/**
 * Return a formated string with the time elpased between now and the specified unix timestamp
 * @param Int $ts    The unix timestamp to get shift from
 * @return string
 */
function getShift($ts){
    
$delta=TIME-$ts;  //TIME is a defined constant with the current timestamp
    
$ret=$str="";
    if(
$delta<=DAY_SECONDS){
        
$str="Today";
    }
    else{
        
$ret=($delta-($delta%DAY_SECONDS))/DAY_SECONDS;
        if(
$ret>=365){
            
$year=($ret-$ret%365)/365;
            
$ret-=$year*365;
            
$str.="$year year";
            if(
$year>1){
                
$str.="s";
            }
        }
        if(
$ret>=30){
            
$month=($ret-$ret%30)/30;
            
$ret-=$month*30;
            if(
$str!=""){
                
$str.=",";
            }
            
$str.=$month month";
            if(
$month>1){
                
$str.="s";
            }
            
            
        }
        if(
$ret<30){
            
$days=$ret%30;
            if(
$str!=""){
                
$str.=" and";
            }
            
$str.=$days day";
            if(
$days>1){
                
$str.="s";
            }
        }
        
        
$str.=" ago ";
        
    }
    return 
$str
}
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-04-2008, 02:47 AM Re: Using date/time's pre 1970-01-01... ?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Well, the math is simple. It's not that. My question is why 1970 matters? Are you tracking bandwidth since before 1970? If so, I'm intrigued, but for other reasons. If you're calculating the number of seconds between 2 times, why do you need something for 1970?

Totally lost here, but confident I can help when I understand...

Oh, and speaking of which, you didn't give me an example of a problem this would solve. That might help clear the fog.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 08-04-2008, 04:28 AM Re: Using date/time's pre 1970-01-01... ?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Jeremy, I simply thought than Dan was mixing date() and time(), and gave him an guessed answer.
I can be totally off track, so yeah, Dan, can you bring us some light here, please.

Thanks.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-04-2008, 10:02 AM Re: Using date/time's pre 1970-01-01... ?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Apologies.

Okay what it is is a SHOUTcast listener time calculator.
http://xdnet.co.uk/clients/shoutcast_bandwidth_calc.php

What it is suposed to do is so user inputs the kb/s of the online feed, selects their shoutcast package (which represents the total allowed bandwidth/month

and it then tells them exactly how many days/hours/minutes they can have thier feed streaming before their bandwidth runs out.

its probably me going at it from the wrong view.

but as you can see if u look at the page it dont work properly the way im doing it as i have like 95 hours and 88 minutes and stuff which is obviously wrong.

PHP Code:
if(isset($_POST['submit']))
{
$kbs $_POST['kbs']; //KB/s of the feed.
$bandwidth $_POST['bandwidth'];

$kb_bandwidth = ($bandwidth*1024)*1024//Total KBS / Month
$total_s $kb_bandwidth/$kbs;
$total_mins$total_s/60;
$total_hrs$total_mins/60;
$total_days=$total_hrs/24;
$total_hr date('Y-m-d H:i:s'$total_s);
#$total = date('d \D\a\y\s H:i', $total_s);
$r_hr substr($total_daysstrrpos($total_days'.') + 1); //Hours left over
$r_hr $r_hr 0.24;
$r_minsubstr($r_hrstrrpos($r_hr'.') + 1); //Remaining Minutes
$c_hrs substr($r_hr02);
$r_min $r_min 0.6;
$c_mins substr($r_min02);
$c_days floor($total_days);

$smartyvalues["c_days"] = $c_days
$smartyvalues["c_hrs"] = $c_hrs
$smartyvalues["c_mins"] = $c_mins
$smartyvalues["total_days"] = $total_days
$smartyvalues["total_hrs"] = $total_hrs
$smartyvalues["total_mins"] = $total_mins
$smartyvalues["kbs"] = $kbs
$smartyvalues["submitted"] = true
okay so theres my bad attempt at hacking it right.

but obviously its not working

if it helps heres the table from the tpl file:
Code:
<table>
 <tr>
  <td>Time</td>
     <td>Value</td>
 </tr>
    
    <tr>
     <td>Days:</td>
        <td>{$c_days}</td>
    </tr>
    <tr>
     <td>Hours:</td>
        <td>{$c_hrs}</td>
    </tr>
    <tr>
     <td>Minutes:</td>
        <td>{$c_mins}</td>
    </tr>
    <tr>
     <td>Total Days:</td>
        <td>{$total_days}</td>
    </tr>
    <tr>
     <td>Total Hours:</td>
        <td>{$total_hrs}</td>
    </tr>
    <tr>
     <td>Total Minutes:</td>
        <td>{$total_mins}</td>
    </tr>
</table>
i am totally confused :s
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 08-04-2008, 01:12 PM Re: Using date/time's pre 1970-01-01... ?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Sorry Tripy. I didn't reply to you, just your post. I thought it was from Dan after I had replied to his first post. Needed to get my head on straight.

Anyway, if you want to convert secondsToDays, here's a function. It doesn't go to the months/years option, but I believe I have a thread on here which takes care of that in an accurate fashion (i.e. accounting for variations in the number of days per month, days per year, etc.).

PHP Code:
<?php
function secondsToDays($total_seconds) {
  
$remaining_seconds $total_seconds;
  
  
$days floor($remaining_seconds/86400);
  
$remaining_seconds -= $days*86400;
  
  
$hours floor($remaining_seconds/3600);
  
$remaining_seconds -= $hours*3600;
  
  
$minutes floor($remaining_seconds/60);
  
$remaining_seconds -= $minutes*60;
  
  return array(
$days$hours$minutes$remaining_seconds);
}
print_r(secondsToDays(86400*12.56));
?>
The result is returned as an array, but that was only for demonstration purposes. You can obviously pull it out of the function altogether.

Hope that helps and, again, sorry Tripy!
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 08-04-2008, 05:29 PM Re: Using date/time's pre 1970-01-01... ?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Thanks, its working now or at least appears to be.

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to Using date/time's pre 1970-01-01... ?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.83849 seconds with 12 queries