Jim Crews
|
| Posted: 02/13/2003, 8:25 AM |
|
In ASP and MySQL
the parameter for the field date_c (datetime in MySQL)
date_c >= date()-45 (expression)
shows from 45 days ago to now in the results on the webpage
Can someone tell me how to do the same thing in PHP and MySQL
Thanks,
Jim Crews
|
|
|
 |
Antonio Manfredonio
|
| Posted: 02/13/2003, 1:32 PM |
|
Try these function to calculate difference between two date
function date_diff($date1, $date2) {
$s = strtotime($date2)-strtotime($date1);
$d = intval($s/86400);
$s -= $d*86400;
$h = intval($s/3600);
$s -= $h*3600;
$m = intval($s/60);
$s -= $m*60;
return array("d"=>$d,"h"=>$h,"m"=>$m,"s"=>$s);
}
|
|
|
 |
Jim Crews
|
| Posted: 02/13/2003, 2:08 PM |
|
Thanks, Antonio
Your example helped me to figure out what I needed
I used
time()-60*60*24*45
to get the webpage to show all records submitted from 45 days ago to now.
I am sure there is better coding, but it works.
Jim
"Antonio Manfredonio" <noone@nowhere.com> wrote in message
news:b2h2u9$3o6$1@news.codecharge.com...
> Try these function to calculate difference between two date
>
> function date_diff($date1, $date2) {
> $s = strtotime($date2)-strtotime($date1);
> $d = intval($s/86400);
> $s -= $d*86400;
> $h = intval($s/3600);
> $s -= $h*3600;
> $m = intval($s/60);
> $s -= $m*60;
> return array("d"=>$d,"h"=>$h,"m"=>$m,"s"=>$s);
> }
>
>
|
|
|
 |
RonB
|
| Posted: 02/15/2003, 4:26 AM |
|
why not use the mysql function directly in the query:
where date_field >= date_sub(now(), interval 45 day)
This way it doesn't matter wich lanuage you are using(php, asp etc) and more
important the database server is doing all the work. In general the database
server can handle these things faster then php ever could.
Ron
"Jim Crews" <jcrews@umcsc.org> schreef in bericht
news:b2h509$82b$1@news.codecharge.com...
> Thanks, Antonio
> Your example helped me to figure out what I needed
> I used
> time()-60*60*24*45
> to get the webpage to show all records submitted from 45 days ago to now.
> I am sure there is better coding, but it works.
> Jim
>
> "Antonio Manfredonio" <noone@nowhere.com> wrote in message
>news:b2h2u9$3o6$1@news.codecharge.com...
> > Try these function to calculate difference between two date
> >
> > function date_diff($date1, $date2) {
> > $s = strtotime($date2)-strtotime($date1);
> > $d = intval($s/86400);
> > $s -= $d*86400;
> > $h = intval($s/3600);
> > $s -= $h*3600;
> > $m = intval($s/60);
> > $s -= $m*60;
> > return array("d"=>$d,"h"=>$h,"m"=>$m,"s"=>$s);
> > }
> >
> >
>
>
|
|
|
 |
Jim Crews
|
| Posted: 02/15/2003, 7:29 PM |
|
RonB,
There is no excuse, so now I am using the mysql function
Thank you.
Jim
"RonB" <r.borkent@123chello123.nl> wrote in message
news:b2lbm4$as$1@news.codecharge.com...
> why not use the mysql function directly in the query:
>
> where date_field >= date_sub(now(), interval 45 day)
>
> This way it doesn't matter wich lanuage you are using(php, asp etc) and
more
> important the database server is doing all the work. In general the
database
> server can handle these things faster then php ever could.
>
> Ron
>
>
> "Jim Crews" <jcrews@umcsc.org> schreef in bericht
>news:b2h509$82b$1@news.codecharge.com...
> > Thanks, Antonio
> > Your example helped me to figure out what I needed
> > I used
> > time()-60*60*24*45
> > to get the webpage to show all records submitted from 45 days ago to
now.
> > I am sure there is better coding, but it works.
> > Jim
> >
> > "Antonio Manfredonio" <noone@nowhere.com> wrote in message
> >news:b2h2u9$3o6$1@news.codecharge.com...
> > > Try these function to calculate difference between two date
> > >
> > > function date_diff($date1, $date2) {
> > > $s = strtotime($date2)-strtotime($date1);
> > > $d = intval($s/86400);
> > > $s -= $d*86400;
> > > $h = intval($s/3600);
> > > $s -= $h*3600;
> > > $m = intval($s/60);
> > > $s -= $m*60;
> > > return array("d"=>$d,"h"=>$h,"m"=>$m,"s"=>$s);
> > > }
> > >
> > >
> >
> >
>
>
|
|
|
 |
|