looping until today

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I want to loop through dates, stopping at the current date

I set the enddate like this

which prints out as '2006-04-01'

$l['cc_startdate'] comes from a DB with the column in date format

but when i do
for ($dl=$l['cc_startdate'];$dl < $enddate;$dl++)
print $dl;


it goes on until the day is 99 and then loops again.
so how do I tell it that $enddate is in the same date format asthe
start date

Re: looping until today

To convert a string to a date, you can use strtotime() to make a timestamp.

So, for example:

echo date ('Y-m-d',strotime('8:30 PM'));

pauld wrote:

Quoted text here. Click to load it

Carl Vondrick

Re: looping until today

 i tried strtitme("now  ") which prints  1143878058 but the loop still
goes round and round


it prints -1 and no loop at  all.

Re: looping until today

pauld contained the following:

Quoted text here. Click to load it

Use timestamps


for ($dl=strtotime('2006-3-1');$dl < $enddate;$dl=$dl+24*60*60)
print date('Y-m-d',$dl)."<br>";

Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

Re: looping until today

thank you . I also need to use the date format as a lookup in an sql

end result  that works

//print he dates from start date to present
for ( $dl=strtotime($l['cc_startdate'])  ;$dl < $enddate ;
//for ($dl=$l['cc_startdate'];$dl < $enddate;$dl++)
//////////////////cell for date
print '<tr><td>'.$dlookup.'</td>';
print '<td>';
$sql2='SELECT * FROM table  WHERE date=''.$dlookup.''';


Site Timeline