Current location: Hot Scripts Forums » Programming Languages » PHP » PEAR array days between two dates


PEAR array days between two dates

Reply
  #1 (permalink)  
Old 03-16-04, 07:30 AM
Dr-Leech Dr-Leech is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Argentina
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Post PEAR array days between two dates

Hi, anyone can help me..
i need to create an array from two dates given.

the array must contain d, m and y of each day between the two dates given.

ie:
Array ("d" => 16, "m" => 3, "y" => 2004);

i think that with PEAR is more easy.. instead a normal function is good too..

Thanks in advance...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-16-04, 11:35 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
if you are getting your date from a timestamp this is how to do what you want:
PHP Code:

//make sure that $timestamp have a valid timestamp..

$date['d'] = date('j'$timestamp);
$date['m'] = date('n'$timestamp);
$date['y'] = date('Y'$timestamp); 
if you are already having the date in DD-MM-YYYY from Mysql for example do this:
PHP Code:

//replace $DDMMYYYY with the date you have ..

$part explode('-'$DDMMYYYY);

$date['d'] = $part[0];
$date['m'] = $part[1];
$date['y'] = $part[2]; 
I used the $array[key] method but you can do the same with $array = array('d' => date('j', $timestamp), ... etc..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 03-16-04, 11:41 AM
Dr-Leech Dr-Leech is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Argentina
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by NeverMind
if you are getting your date from a timestamp this is how to do what you want:
PHP Code:

 //make sure that $timestamp have a valid timestamp..
 
$date['d'] = date('j'$timestamp);
 
$date['m'] = date('n'$timestamp);
 
$date['y'] = date('Y'$timestamp); 
if you are already having the date in DD-MM-YYYY from Mysql for example do this:
PHP Code:

 //replace $DDMMYYYY with the date you have ..
 
$part explode('-'$DDMMYYYY);
 
 
$date['d'] = $part[0];
 
$date['m'] = $part[1];
 
$date['y'] = $part[2]; 
I used the $array[key] method but you can do the same with $array = array('d' => date('j', $timestamp), ... etc..
Thanks.. i've solved it with this:
PHP Code:

 function arrayEntreFechas($primerFecha$segundaFecha) {
     
$f1 explode("-"$primerFecha);
     
$f1 mktime(0,0,0,$f1[1],$f1[0],$f1[2]);
     
     
$f2 explode("-"$segundaFecha);
     
$f2 mktime(0,0,0,$f2[1],$f2[0],$f2[2]);
 
     
$fechaMasUno $f1;
     
$c 0;
     while (
$fechaMasUno != $f2) {
         
$fechaMasUno += 86400;
         
$tmp explode("-"date("d-m-Y",$fechaMasUno));
         
$tmpArray[$c] = array("d" => $tmp[0], "m" => $tmp[1], "y" => $tmp[2]);
         
         
$c++;
     }
     
     return 
$tmpArray;    
 } 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional Array Sorting Kage PHP 6 12-12-05 05:19 PM
registration of prodid,name,and 2 dates pr. month ropey PHP 3 01-31-04 02:12 PM
linking to iframe not working :( j0d JavaScript 5 01-19-04 09:14 PM
asp: values in array not in order?? seala ASP 0 08-16-03 01:06 PM
leave calculation vioss PHP 0 08-03-03 11:18 PM


All times are GMT -5. The time now is 07:28 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.