Re: Problem in FOR loop
От | Jonathan Wright |
---|---|
Тема | Re: Problem in FOR loop |
Дата | |
Msg-id | 20030501130733.GA12934@chef.djnauk.cx обсуждение исходный текст |
Ответ на | Problem in FOR loop ("Ramesh PAtel " <ramesh@banas.guj.nic.in>) |
Список | pgsql-novice |
Ramesh PAtel thus noted: > Hi All > > please give one help > > I want to us date variable in for loop Condition. in PHP > > But it not working Properly. > $dt='2003-04-22' ; > $to='2003-04-30'; > > FOR ( $dt=$dt; $dt > $to ; ) > { > print "XYz"; > } > > Please Help me > > and how to file date diff in Day please Help That won't work as there is nothing to increment the date within the for loop: for (<set variable>;<exit condition>;<condition modifier>); You would need some that would take the date and increment it. One output would be to use the mktime function to convert the date into timestamp and then use that for the comparison --8<-------------- function from_date($date) { list($year, $month, $date) = explode("-", $date) { return mktime(0, 0, 0, $month, $day, $year); } function to_date($date) { return date("Y-m-d", $date); } $dt='2003-04-22'; $to='2003-04-30'; for ( ; from_date($dt) > from_date($to); $dt = to_date(from_date($dt)+(60*60*24))) { print "XYz"; } --8<-------------- I'm not sure if PHP can handle dates like you want, but that's one way around the problem.... -- jonathan wright mail at djnauk.co.uk | www.djnauk.co.uk -- life has no meaning unless we can enjoy what we've been given
В списке pgsql-novice по дате отправления: