p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: DATE


Message #1 by "Darren Spink" <dvs1@b...> on Fri, 13 Sep 2002 11:39:23 +0100
This will be an easy couple of questions for someone.

1)  How do I put the current date (date/time would do) into a record when I
store the record in a MySQL database.

2)  I want to search the same database for records stored within the last
day, 3 days and 7 days.

Thanks in advance.


Regards


Darren


Message #2 by "Comsolve - Administrator" <administrator@c...> on Fri, 13 Sep 2002 13:06:32 +0200
err.. the option NOW() would do the trick...

$query =3D "INSERT INTO $DBaccesstable (usernumber,accessdate)
                             VALUES( '$usernumber', NOW())" ;

the option NOW() produces a value like this :

20020512190200

and a query that would help with searching you would be something like 
this :

$querylastday =3D "SELECT something FROM tbl_name WHERE TO_DAYS(NOW()) - 
TO_DAYS(date_col) <=3D 1";

$querylast3days =3D "SELECT something FROM tbl_name WHERE TO_DAYS(NOW()) 
- TO_DAYS(date_col) <=3D 3";

$querylast7days =3D "SELECT something FROM tbl_name WHERE TO_DAYS(NOW()) 
- TO_DAYS(date_col) <=3D 7";


For a complete overview take a look on this page :

http://www.mysql.com/doc/en/Date_and_time_functions.html

hope i did it all ok.. please correct me when i mis-explained anything..

Michael


-----Oorspronkelijk bericht-----
Van: Darren Spink [mailto:dvs1@b...]
Verzonden: Friday, September 13, 2002 12:39
Aan: beginning php
Onderwerp: [beginning_php] DATE



This will be an easy couple of questions for someone.

1)  How do I put the current date (date/time would do) into a record 
when I
store the record in a MySQL database.

2)  I want to search the same database for records stored within the 
last
day, 3 days and 7 days.

Thanks in advance.


Regards


Darren



Message #3 by "Darren Spink" <dvs1@b...> on Fri, 13 Sep 2002 13:46:52 +0100
Spot on, Thanks Michael

Regards


Darren 


  Return to Index