RE: [PHP-DB] difference between two dates

2003-01-19 Thread John W. Holmes
 In my application I am accepting Day, Month and Year from a Select
List.
 What I want to do is calculate the age of the person based on the
above
 selection.
 
 $cboDD is the day variable
 $cboMM is the month variable
 $cboYY is the year variable
 
 I tried this :
 
 $dobtimestamp = mktime(0,0,0,$cboMM,$cboDD,$cboYY);
 $todaytimestamp = time();
 $txtAge = ($todaytimestamp - $dobtimestamp)/86400;
 
 It does not give me the expected output.
 
 Can anybody suggest something ?

Keep your mktime() as it is, that's correct. Then use something like
this to calculate the age:

$age = date('Y',$now) - date('Y',$dob) -
((date('z',$now)=date('z',$dob)) ? 0 : 1);

where $dob and $now are the appropriate unix timestamps that you've
already got calculated with mktime() and time().

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] difference between two dates

2003-01-19 Thread Rajesh Fowkar
On Sun, Jan 19, 2003 at 09:34:02AM -0500, John W. Holmes wrote:

 I tried this :
 
 $dobtimestamp = mktime(0,0,0,$cboMM,$cboDD,$cboYY);
 $todaytimestamp = time();
 $txtAge = ($todaytimestamp - $dobtimestamp)/86400;
 
 It does not give me the expected output.
 
 Can anybody suggest something ?

Keep your mktime() as it is, that's correct. Then use something like
this to calculate the age:

$age = date('Y',$now) - date('Y',$dob) -
((date('z',$now)=date('z',$dob)) ? 0 : 1);

where $dob and $now are the appropriate unix timestamps that you've
already got calculated with mktime() and time().

Thanks a lot. 

Peace

--
Rajesh
:
[ GNU/Linux One Stanza Tip (LOST) ]###

Sub : ext3 file system   LOST #034

To implement ext3 filesystem have a good look here (Cool) :
http://www.uow.edu.au/~andrewm/linux/ext3/ext3-usage.html

[EMAIL PROTECTED]###
:

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Difference between 2 dates.. thoughts?

2002-11-13 Thread Jason Vincent
You should be able to do this at the database level - of course you never
said what database that is.

Regardless, check your database documentation for the max() and min()
functions - never used these on date but they might work - do you always
want the first record and the last record in the database?  Or do you mean
the first and last record of the record set?  If you always want the first
record inserted and the last record inserted, than use max() and min() in
the unique database key (the unique record number) assuming you have one and
that they are sequential.

Then check for any date functions that might be able to tell the days
elapsed between to dates (in mySQL you might look at the interval function).

Regards,

J


-Original Message-
From: Aaron Wolski [mailto:aaronjw;martekbiz.com] 
Sent: Wednesday, November 13, 2002 11:33 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Difference between 2 dates.. thoughts?


Hi All,
 
First off I have a query like this:
 
SELECT dateinserted FROM SiteTrackingTable;
 
Now. in this query any number of results could be returned 10 or 1000, etc.
 
Is it possible to take the dateinserted value from the first record and then
from the last record and perform some calculation to get the number of days
the record spans?
 
Haven't done something like this before and don't have a clue where to
start. Date sorting,etc I can do just don't know about this one.
 
Thanks for your help!
 
Aaron



RE: [PHP-DB] Difference between 2 dates.. thoughts?

2002-11-13 Thread Aaron Wolski
Hi There,

Well the first and last record of the results.

So if 1000 records were found... then record #1 and then record #1000 -
perform data calculation between those 2 records (how many days does
this query span).

Know what I am trying to say?

Sorry if its not clear.

Aaron

-Original Message-
From: Jason Vincent [mailto:jayv;nortelnetworks.com] 
Sent: November 13, 2002 12:24 PM
To: Aaron Wolski; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Difference between 2 dates.. thoughts?

You should be able to do this at the database level - of course you
never
said what database that is.

Regardless, check your database documentation for the max() and min()
functions - never used these on date but they might work - do you always
want the first record and the last record in the database?  Or do you
mean
the first and last record of the record set?  If you always want the
first
record inserted and the last record inserted, than use max() and min()
in
the unique database key (the unique record number) assuming you have one
and
that they are sequential.

Then check for any date functions that might be able to tell the days
elapsed between to dates (in mySQL you might look at the interval
function).

Regards,

J


-Original Message-
From: Aaron Wolski [mailto:aaronjw;martekbiz.com] 
Sent: Wednesday, November 13, 2002 11:33 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Difference between 2 dates.. thoughts?


Hi All,
 
First off I have a query like this:
 
SELECT dateinserted FROM SiteTrackingTable;
 
Now. in this query any number of results could be returned 10 or 1000,
etc.
 
Is it possible to take the dateinserted value from the first record and
then
from the last record and perform some calculation to get the number of
days
the record spans?
 
Haven't done something like this before and don't have a clue where to
start. Date sorting,etc I can do just don't know about this one.
 
Thanks for your help!
 
Aaron



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Difference between 2 dates.. thoughts?

2002-11-13 Thread Jason Vincent
Test whether min() and max() work on date fields - never tried it.  Or check
the documentation on date and time functions for your database - they may
have something that does this.

If not, you could just do an order by date ascending and grab only the first
record, then an order by date descending and grab the first record of that.
Then you would need to use some date function (or php date module) to find
the span.  If you are using mysql, check out the INTERVAL function.

Regards,

J


-Original Message-
From: Aaron Wolski [mailto:aaronjw;martekbiz.com] 
Sent: Wednesday, November 13, 2002 12:27 PM
To: Vincent, Jason [BRAM:1334:EXCH]; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Difference between 2 dates.. thoughts?


Hi There,

Well the first and last record of the results.

So if 1000 records were found... then record #1 and then record #1000 -
perform data calculation between those 2 records (how many days does this
query span).

Know what I am trying to say?

Sorry if its not clear.

Aaron

-Original Message-
From: Jason Vincent [mailto:jayv;nortelnetworks.com] 
Sent: November 13, 2002 12:24 PM
To: Aaron Wolski; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Difference between 2 dates.. thoughts?

You should be able to do this at the database level - of course you never
said what database that is.

Regardless, check your database documentation for the max() and min()
functions - never used these on date but they might work - do you always
want the first record and the last record in the database?  Or do you mean
the first and last record of the record set?  If you always want the first
record inserted and the last record inserted, than use max() and min() in
the unique database key (the unique record number) assuming you have one and
that they are sequential.

Then check for any date functions that might be able to tell the days
elapsed between to dates (in mySQL you might look at the interval function).

Regards,

J


-Original Message-
From: Aaron Wolski [mailto:aaronjw;martekbiz.com] 
Sent: Wednesday, November 13, 2002 11:33 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Difference between 2 dates.. thoughts?


Hi All,
 
First off I have a query like this:
 
SELECT dateinserted FROM SiteTrackingTable;
 
Now. in this query any number of results could be returned 10 or 1000, etc.
 
Is it possible to take the dateinserted value from the first record and then
from the last record and perform some calculation to get the number of days
the record spans?
 
Haven't done something like this before and don't have a clue where to
start. Date sorting,etc I can do just don't know about this one.
 
Thanks for your help!
 
Aaron





RE: [PHP-DB] Difference between 2 dates.. thoughts?

2002-11-13 Thread Aaron Wolski
Ok,
 
Thanks for your input. I know very little about how to manipulate MySQL
so this out to be fun and very slow going :-(
 
Thanks!
 
Aaron
 
-Original Message-
From: Jason Vincent [mailto:jayv;nortelnetworks.com] 
Sent: November 13, 2002 12:34 PM
To: Aaron Wolski; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Difference between 2 dates.. thoughts?
 
Test whether min() and max() work on date fields - never tried it.  Or
check the documentation on date and time functions for your database -
they may have something that does this.
If not, you could just do an order by date ascending and grab only the
first record, then an order by date descending and grab the first record
of that.  Then you would need to use some date function (or php date
module) to find the span.  If you are using mysql, check out the
INTERVAL function.
Regards, 
J 
 
-Original Message- 
From: Aaron Wolski [mailto:aaronjw;martekbiz.com] 
Sent: Wednesday, November 13, 2002 12:27 PM 
To: Vincent, Jason [BRAM:1334:EXCH]; [EMAIL PROTECTED] 
Subject: RE: [PHP-DB] Difference between 2 dates.. thoughts? 
 
Hi There, 
Well the first and last record of the results. 
So if 1000 records were found... then record #1 and then record #1000 -
perform data calculation between those 2 records (how many days does
this query span).
Know what I am trying to say? 
Sorry if its not clear. 
Aaron 
-Original Message- 
From: Jason Vincent [mailto:jayv;nortelnetworks.com] 
Sent: November 13, 2002 12:24 PM 
To: Aaron Wolski; [EMAIL PROTECTED] 
Subject: RE: [PHP-DB] Difference between 2 dates.. thoughts? 
You should be able to do this at the database level - of course you
never said what database that is. 
Regardless, check your database documentation for the max() and min()
functions - never used these on date but they might work - do you always
want the first record and the last record in the database?  Or do you
mean the first and last record of the record set?  If you always want
the first record inserted and the last record inserted, than use max()
and min() in the unique database key (the unique record number) assuming
you have one and that they are sequential.
Then check for any date functions that might be able to tell the days
elapsed between to dates (in mySQL you might look at the interval
function).
Regards, 
J 
 
-Original Message- 
From: Aaron Wolski [mailto:aaronjw;martekbiz.com] 
Sent: Wednesday, November 13, 2002 11:33 AM 
To: [EMAIL PROTECTED] 
Subject: [PHP-DB] Difference between 2 dates.. thoughts? 
 
Hi All, 
  
First off I have a query like this: 
  
SELECT dateinserted FROM SiteTrackingTable; 
  
Now. in this query any number of results could be returned 10 or 1000,
etc. 
  
Is it possible to take the dateinserted value from the first record and
then from the last record and perform some calculation to get the number
of days the record spans?
  
Haven't done something like this before and don't have a clue where to
start. Date sorting,etc I can do just don't know about this one.
  
Thanks for your help! 
  
Aaron 
 



RE: [PHP-DB] Difference in time

2002-10-02 Thread Jason Vincent

for mySQL, the table would look like...
 
CREATE TABLE polls(
 pollID INT NOT NULL AUTO_INCREMENT,
 ipAddress VARCHAR (50) NULL,
 insertTime DATETIME NULL,
 etc...
 
 PRIMARY KEY (pollID)
);
 
===
the code would look like...

$statement = select pollID from polls where insertTime  (now() - INTERVAL
1 HOUR);  //see mySQL date time functions for a description of this
$result = mysql_query($statement);
$rowsReturned = mysql_num_rows($result);
 
if($rowsReturned){
 print Sorry you already voted in the last hour;
}else{
 insert into polls (ipAddress,insertTime) values ('$ipAddress',now());
}
 

P.S. - now() is a database function that will insert the time for you
(mySQL is usually -dd-mm hh:mm:ss)

-Original Message-
From: wade [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, October 02, 2002 2:56 PM
To: Vincent, Jason [BRAM:1334:EXCH]
Subject: Re: [PHP-DB] Difference in time


MYSQL 

Here is a sample of what I am doing 
  


$ip = $_SERVER['REMOTE_ADDR']; 
$time_now = mktime(); 
  
// open connection to database 
$connection = mysql_connect($hostname, $user, $pass) or die (Unable
to connect!); 
  
// get the IP and stored DB time 
$query = SELECT ip_address, server_time 
 FROM stats 
WHERE ip_address = '$ip'; 
$result = mysql_db_query($database, $query, $connection) or die
(Error in query: $query.  . mysql_error()); 
  
$row = mysql_fetch_array($result); 
$get_ip = $row['ip_address']; 
$get_server_time = $row['server_time']; 
  
// close connection 
mysql_close($connection); 
mysql_free_result($result); 
  
if ($ip == $get_ip) 
{ 
$connection = mysql_connect($hostname, $user, $pass) or die
(Unable to connect!); 
$query=select * from stats where server_time  'now()- 1
hour' and ip_address = '$ip'; 
$result = mysql_db_query($database, $query, $connection) or
die (Error in query: $query.  . mysql_error()); 
  
$row = mysql_fetch_array($result); 
$get_ip2 = $row['ip_address']; 
$get_server_time2 = $row['server_time']; 
// close connection 
mysql_close($connection); 
mysql_free_result($result); 
  
if ($get_server_time2) 
{ 
echo Sorry cannot vote; 
exit; 
} 
} 


Jason Vincent wrote: 


  

what kind of database are you using? 


-Original Message- 
From: wade [mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] ] 
Sent: Wednesday, October 02, 2002 2:47 PM 
To: Vincent, Jason [BRAM:1334:EXCH] 
Subject: Re: [PHP-DB] Difference in time 


One question on this issue. What should I store in the database mktime( ).
time( )? 


Jason Vincent wrote: 


 yeah - the mktime function is returning unix style time (seconds since 
 1970) which is why only the last few numbers are changing.  I would 
 recommend letting the database decide who is able to submit... i.e. 
 
 select * from database where lastSubmitDate  'now()- 1 hour' and IP = 
 '$ipaddress' 
 
 if there is a returned record from the database, you know that this 
 person has made a submission in the last hour.  Otherwise, let them 
 submit again 
 
 Obviously, you will need to figure out the sytax for the now() -1 hour 
 part depending on your database. 
 
 -Original Message- 
 From: wade [mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] ] 
 Sent: Wednesday, October 02, 2002 1:29 PM 
 To: [EMAIL PROTECTED] 
 Subject: [PHP-DB] Difference in time 
 
 Hello all, 
 
 I am fighting a time issue(don't we all). I have a online poll set up. 
 I need a way to stop a person from submitting more than once an hour. 
 As of now I have the time .. mktime( 
 ) .. being stored in a database along 
 with the users IP. 
 
 I want to be able to say if 1 hour has passed from the time .. mktime( 
 ) .. that is stored in the db they can vote once again. This also has 
 to account that if someone goes to the poll tomorrow at the same time 
 (same 
 hour) the script knows it's a different hour and different day. 
 
 Scenario: I submit to the poll at 12:00 PM, one hour from now will be 
 1:00 PM and I can submit again. Now lets say it's 12:00 PM the next 
 day. The database stored time will say 12:00 PM of the day before, It 
 will not let me submit because it thinks that it has to be at least 
 1:00 PM before I can submit again. Which is wrong. 
 
 I was trying to use the mktime( ) function but it keeps giving me 
 these results.(( 1033578795 )) The last few numbers change but the 
 first few (that as suppose to be the hour) does not change? mktime(int 
 hour, int minute, int second, int month, int day, int year). How can I 
 use this mktime( ) function to do what I need it to? Am I going

RE: [PHP-DB] Difference in time

2002-10-02 Thread John W. Holmes

 I am fighting a time issue(don't we all). I have a online poll set up.
I
 need a way to stop a person from
 submitting more than once an hour. As of now I have the time ..
mktime(
 ) .. being stored in a database along
 with the users IP.
 
 I want to be able to say if 1 hour has passed from the time .. mktime(
)
 .. that is stored in the db they can vote once again. This also has to
 account that if someone goes to the poll tomorrow at the same time
(same
 hour) the script knows it's a different hour and different day.
 
 Scenario: I submit to the poll at 12:00 PM, one hour from now will be
 1:00 PM and I can submit again. Now lets
 say it's 12:00 PM the next day. The database stored time will say
12:00
 PM of the day before, It will not let me submit because it thinks that
 it has to be at least 1:00 PM before I can submit again. Which is
wrong.
 
 I was trying to use the mktime( ) function but it keeps giving me
these
 results.(( 1033578795 )) The last few
 numbers change but the first few (that as suppose to be the hour) does
 not change?
 mktime(int hour, int minute, int second, int month, int day, int
year).
 How can I use this mktime( ) function to do what I need it to? Am I
 going in the wrong direction?

SELECT 1 FROM table WHERE FROM_UNIXTIME(last_post)  (NOW() - INTERVAL 1
HOUR) AND User_ID = XXX

If a row is returned, then the user is clear to vote, it's been over an
hour.

---John Holmes...



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] difference !!??

2002-02-07 Thread Daniel Ems

Bart,

See this page for an explanation of quotes inside array brackets:

http://www.php.net/manual/en/language.types.array.php

Basically, the correct way to do it is to _always_ use quotes (single
quotes for strings without variables, and double quotes for strings with
variables).  So your example below should use format #2 since there are no
variables to expand.  Format #1 below is deprecated, and I can attest to
weird behavior when you use $row[$column_name] without double quotes.  
Hope this helps!

Daniel Ems


On Thu, 7 Feb 2002, B. Verbeek wrote:
 Hello,
 
 What's the difference between:
 
 1.- $row[column_name];
 2.- $row['column_name'];
 3.- $row[column_name];
 
 ?
 
 ragards Bart
 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Difference between OCI* functions and ORA_* functions

2001-10-05 Thread Philippe Saladin

FYI, You can use OCI8 on a Oracle 7 database, if the net8 client is
configured
Regards,
Philippe

B. Perrine [EMAIL PROTECTED] a écrit dans le message news:
[EMAIL PROTECTED]
ORA are for Oracle7
OCI8 for Oracle8

Read the manual on www.php.net
B.

le jeu 04-10-2001 at 17:02 Sridhar Moparthy a écrit :
 Hi All,

 Does any one know the difference between OCI* functions from PHP_OCI8.DLL
 and ORA_* functions  from PHP_ORACLE.DLL?
 Which one is better in terms of speed and which one is better for future
 compatibility?.

 Thanks in advance
 Sridhar Moparthy.


 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]





-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Difference between OCI* functions and ORA_* functions

2001-10-04 Thread B. PERRINE

ORA are for Oracle7
OCI8 for Oracle8

Read the manual on www.php.net
B. 

le jeu 04-10-2001 at 17:02 Sridhar Moparthy a écrit :
 Hi All,
 
 Does any one know the difference between OCI* functions from PHP_OCI8.DLL
 and ORA_* functions  from PHP_ORACLE.DLL?
 Which one is better in terms of speed and which one is better for future
 compatibility?.
 
 Thanks in advance
 Sridhar Moparthy.
 
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]