CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> Archive -> CodeChargeStudio.Discussion

 Date based query

Print topic Send  topic

Author Message
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);
> > > }
> > >
> > >
> >
> >
>
>


   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.