Some advaced stuff (I think)

This is a discussion on "Some advaced stuff (I think)" within the PHP Forum section. This forum, and the thread "Some advaced stuff (I think) are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Dec 1st, 2007, 13:01
New Member
Join Date: Nov 2007
Location: Hungary
Age: 22
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Some advaced stuff (I think)

Hi!

In the past few years I'm getting better and better at PHP programming, and I feel I can do alot with it now. I haven't learnt it in school, but by myself.

I'm now working on a project I started. A database based stuff for our family business, a video library. It can do alot now, and I worked quite hard on it. And I've arrived to a difficult piece.

I have to count the money for the movies which are arrived back late to us. And I have to count the days of the expired lendings, so I'mhaving a though time.

I save the lending date and in a mysql table (5 colums year, month, day, hour and minutes)...

I need to count that how many days have passed since the particular date I've stored in the database. And I'm having a hard time count which moinths have 30 or 31 days or when february has 28 or 29.

I'm asking you if there is any piece of code or a function in php or maybe javascript which can count the days from a certain date to another (which will mostly be the present date and time).

I hope someone could help me with that. And Please forgive me for my bad english!
Reply With Quote

  #2 (permalink)  
Old Dec 1st, 2007, 13:18
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
Re: Some advaced stuff (I think)

date('t',[timestamp]) returns the number of days in a month.
Reply With Quote
  #3 (permalink)  
Old Dec 1st, 2007, 13:51
New Member
Join Date: Nov 2007
Location: Hungary
Age: 22
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Some advaced stuff (I think)

I will definately use that one. Thank you very much.

But I'm trying to find an easier way...

For example: I define a date(y-m-d h:m) I don't know exactléy how it is done but I'll manage.
Then I will define another day: for example the current date(), and I need a function or something that counts days months and maybe hour between the two dates.

I don't know if such function or script exists...
Reply With Quote
  #4 (permalink)  
Old Dec 2nd, 2007, 09:23
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
Re: Some advaced stuff (I think)

How about writing it yourself... not at all hard...

1. convert the two dates into unix timestamps (time() function).
2. subtract timestamp1 from timestamp2.
3. convert to seconds into months/days/hours/min/sec. Here's a function I wrote for converting seconds (only hours/mins/secs):
PHP: Select all

function formatSecondsToString($num_sec) {
    if(
$num_sec<60) {
        return 
$num_sec.($num_sec==1?' second':' seconds');
    } else if(
$num_sec<3600) {
        
$m=floor($num_sec/60);
        
$s=$num_sec%60;
        return 
$m.($m==1?' minute':' minutes').($s==0?'':(' and '.$s.($s==1?' second':' seconds')));
    } else {
        
$h=floor($num_sec/3600);
        
$m=$num_sec%3600;
        
$s=$m%60;
        
$m=floor($m/60);
        return 
$h.($h==1?' hour':' hours').($m==0?'':(', '.$m.($m==1?' minute':' minutes'))).($s==0?'':(' and '.$s.($s==1?' second':' seconds')));
    }

Reply With Quote
Reply

Thread Tools

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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
what are this stuff? geyids Web Page Design 2 Aug 7th, 2007 17:17


All times are GMT. The time now is 07:31.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43