RE: [PHP] Date functions differences between php 4 and 5

2007-03-22 Thread Jake McHenry

I just asked this a bit ago. Time and Date seem to be the same, but
strtotime is definitly different, as that was what broke in my script in
php4, and I was told it worked as expected in php5.
 

> -Original Message-
> From: Chris [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, March 22, 2007 7:18 PM
> To: Paul Nowosielski
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Date functions differences between php 4 and 5
> 
> Paul Nowosielski wrote:
> > Dear All,
> > 
> > I was wondering if there are any major date function 
> changes between php4 and 
> > 5.
> 
> I don't think so but check the docs: 
> http://www.php.net/manual/en/faq.migration5.php
> 
> > When I say date function I mean mktime() , date() ,strtotime() etc.
> > 
> > Here is my dilemma, I've upgraded from php4 to php5. there 
> is some very old 
> > legacy code that is not working correctly. 
> > 
> > Specifically on our sales calendar.  Some task show up but 
> most don't.
> > I have the old site and the new upgraded site on the same db.
> > When entering a new task on the calendar, tasks enter w/ 
> the new system show 
> > up on the new system and not on the old. Most old tasks 
> don't show up on the 
> > new.
> 
> That could be a register_globals issue - there's no way for 
> us to know 
> what's going on without seeing the code.
> 
> Time to start digging.
> 
> -- 
> Postgresql & php tutorials
> http://www.designmagick.com/
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> -- 
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.446 / Virus Database: 268.18.17/730 - Release 
> Date: 3/22/2007 7:44 AM
>  
> 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.17/730 - Release Date: 3/22/2007
7:44 AM
 

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



Re: [PHP] Date functions differences between php 4 and 5

2007-03-22 Thread Chris

Paul Nowosielski wrote:

Dear All,

I was wondering if there are any major date function changes between php4 and 
5.


I don't think so but check the docs: 
http://www.php.net/manual/en/faq.migration5.php



When I say date function I mean mktime() , date() ,strtotime() etc.

Here is my dilemma, I've upgraded from php4 to php5. there is some very old 
legacy code that is not working correctly. 


Specifically on our sales calendar.  Some task show up but most don't.
I have the old site and the new upgraded site on the same db.
When entering a new task on the calendar, tasks enter w/ the new system show 
up on the new system and not on the old. Most old tasks don't show up on the 
new.


That could be a register_globals issue - there's no way for us to know 
what's going on without seeing the code.


Time to start digging.

--
Postgresql & php tutorials
http://www.designmagick.com/

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



[PHP] Date functions differences between php 4 and 5

2007-03-22 Thread Paul Nowosielski
Dear All,

I was wondering if there are any major date function changes between php4 and 
5.

When I say date function I mean mktime() , date() ,strtotime() etc.

Here is my dilemma, I've upgraded from php4 to php5. there is some very old 
legacy code that is not working correctly. 

Specifically on our sales calendar.  Some task show up but most don't.
I have the old site and the new upgraded site on the same db.
When entering a new task on the calendar, tasks enter w/ the new system show 
up on the new system and not on the old. Most old tasks don't show up on the 
new.

The code is a pretty bad hack (why use the echo statement once when you can 
use it 207 times).

www:/srv/www/htdocs/admin # grep -ic "echo" calendar/calendar.html
207



Any knowledge of this would be greatly appreciated.

Thank you, 
-- 
Paul Nowosielski
Webmaster 

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



[PHP] mysql/php date functions..

2005-09-26 Thread info
Hello Bruce,
While the date functions are well documented - http://php.net/date - here is a 
little example to manipulate the date with php, rather than mysql:

// set the new expiry date
// DATE FUNCTIONS FOR THE EXPIRY MODULE
// first perform date arithmetic
$listingExpiry = mktime (0,0,0,date("m")+$monthsGoodFor,date("d")+1,date("Y"));
// secondly, format the results for use in the database
$expires = date ("Y-m-d", $listingExpiry);
// the actual update of the database with expires='$expires' ... should be 
below here

The date format to be used in $expires depends on your database column 
structure.

Rob.
http://www.globalissa.com

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



RE: [PHP] mysql/php date functions..

2005-09-26 Thread Chrome
Hi

The PHP time() function returns the number of seconds since the Unix epoch
(Jan 1 1970 midnight) whereas MySQL uses a readable datestamp

See here:

http://dev.mysql.com/doc/mysql/en/datetime.html

for the MySQL date, time and date/time types

and here

http://uk.php.net/manual/en/function.time.php

for time()... instead of using time(), use date() and format it for MySQL

http://uk.php.net/manual/en/function.date.php

That will allow you to use < and > in the SQL statements

HTH


Chrome™
http://www.chrome.me.uk


-Original Message-
From: bruce [mailto:[EMAIL PROTECTED] 
Sent: 26 September 2005 19:46
To: 'John Nichel'; php-general@lists.php.net
Subject: RE: [PHP] mysql/php date functions..

john...

that appears to be it!! although i would have assumes it would have done a
most significant bit fill with 0's...

so my question also comes down to .. do i use the php date functions for
date/time manipulation.. or do i use the mysql functions

any thoughts/suggestions...

-bruce


-Original Message-
From: John Nichel [mailto:[EMAIL PROTECTED]
Sent: Monday, September 26, 2005 11:19 AM
To: php-general@lists.php.net
Subject: Re: [PHP] mysql/php date functions..


bruce wrote:
> thanks...
>
> but that's not it john... i'm not worried about creating the sql_statement
> in the php...
>
> i'm concerned that i can't seem to craft/create a basic sql cmd within
mysql
> to get a value (other than NOW()) to work...
>
> if i do (from mysql)
>  -->> insert into foo (id, time) values (2, 33), it doesn't work...
> if i
>  -->> insert into foo (id, time) values (2, NOW()), it works!!...
>
> my question is why???

Without knowing the structure of your table, my guess is that the column
time is expecting a valid timestamp, and 33 is not a valid MySQL
timestamp.

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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

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

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



Re: [PHP] mysql/php date functions..

2005-09-26 Thread John Nichel

Chris W. Parker wrote:

John Nichel 
on Monday, September 26, 2005 12:43 PM said:



I don't convert it.  I store the UNIX timestamp in an INT(11) column.



This is going to be a basic question I'm sure but why INT and not
VARCHAR? Is it simply because a timestamp is a number?


Yep.  Course, I may be doing it wrong.  Wouldn't be the first time. ;)


--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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



Re: [PHP] mysql/php date functions..

2005-09-26 Thread Kristen G. Thorson
Read up on mysql date types and functions.  You can convert a unix 
timestamp to a mysql date with the FROM_UNIXTIME() function.  If you 
want to store as unix timestamp, store it in an int field.  To use mysql 
date functions on it, use the FROM_UNIXTIME() function.  If you want to 
store dates in mysql timestamp fields, use in a select statement a) 
UNIX_TIMESTAMP() or b) DATE_FORMAT() to a) convert to unix timestamp and 
process with PHP or b) format date for output.



http://dev.mysql.com/doc/mysql/en/date-and-time-types.html
http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html


kgt



bruce wrote:


or.. better yet.

if i do a php -> time(), i get a unix_timestamp var. how do you guys store
this in mysql. you can't simply do an insert into a mysql/timestamp var. so
how do you convert it?

also, once you have the mysql tbl, how do you go from the mysql timestamp
var ->> the php var?

thanks

bruce


-Original Message-
From: bruce [mailto:[EMAIL PROTECTED]
Sent: Monday, September 26, 2005 12:38 PM
To: 'John Nichel'; php-general@lists.php.net
Subject: RE: [PHP] mysql/php date functions..


so you play with the time/date vars on the php side, and then simply store
them in the mysql tbl as a int(10)... or do you actually store the vars in
the mysql timestamp...

and then use the mysql date/time functions...

ie. how would you do the following...

get a date (date1)
get a date (date2)
store the date1/time in mysql
add the date1 + date2 and store the result in mysql
read the result from mysql, with the result being in the year/month/date
format

--

or,

would you just get the unix_timestamp representation of the dates, and store
the 10 int formats in the mysql tbl. you could then extract/select the date
information from the tbls, and do all the date calculations in php...

the downside to this is that you'd have to convert all the date information
from mysql to a human readable format...

thoughts/comments/etc...

-bruce


-Original Message-
From: John Nichel [mailto:[EMAIL PROTECTED]
Sent: Monday, September 26, 2005 11:48 AM
To: php-general@lists.php.net
Subject: Re: [PHP] mysql/php date functions..


bruce wrote:
 


john...

that appears to be it!! although i would have assumes it would have done a
most significant bit fill with 0's...

so my question also comes down to .. do i use the php date functions for
date/time manipulation.. or do i use the mysql functions

any thoughts/suggestions...

-bruce
   



Personal preference I guess.  Me, I use UNIX timestamps.

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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

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

 



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



RE: [PHP] mysql/php date functions..

2005-09-26 Thread Chris W. Parker
John Nichel 
on Monday, September 26, 2005 12:43 PM said:

> I don't convert it.  I store the UNIX timestamp in an INT(11) column.

This is going to be a basic question I'm sure but why INT and not
VARCHAR? Is it simply because a timestamp is a number?



Chris.

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



Re: [PHP] mysql/php date functions..

2005-09-26 Thread John Nichel

bruce wrote:

or.. better yet.

if i do a php -> time(), i get a unix_timestamp var. how do you guys store
this in mysql. you can't simply do an insert into a mysql/timestamp var. so
how do you convert it?


I don't convert it.  I store the UNIX timestamp in an INT(11) column.


also, once you have the mysql tbl, how do you go from the mysql timestamp
var ->> the php var?


Since I keep it in the UNIX timestamp format, there's no converting 
between the two.


--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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



RE: [PHP] mysql/php date functions..

2005-09-26 Thread bruce
or.. better yet.

if i do a php -> time(), i get a unix_timestamp var. how do you guys store
this in mysql. you can't simply do an insert into a mysql/timestamp var. so
how do you convert it?

also, once you have the mysql tbl, how do you go from the mysql timestamp
var ->> the php var?

thanks

bruce


-Original Message-
From: bruce [mailto:[EMAIL PROTECTED]
Sent: Monday, September 26, 2005 12:38 PM
To: 'John Nichel'; php-general@lists.php.net
Subject: RE: [PHP] mysql/php date functions..


so you play with the time/date vars on the php side, and then simply store
them in the mysql tbl as a int(10)... or do you actually store the vars in
the mysql timestamp...

and then use the mysql date/time functions...

ie. how would you do the following...

 get a date (date1)
 get a date (date2)
 store the date1/time in mysql
 add the date1 + date2 and store the result in mysql
 read the result from mysql, with the result being in the year/month/date
format

--

or,

would you just get the unix_timestamp representation of the dates, and store
the 10 int formats in the mysql tbl. you could then extract/select the date
information from the tbls, and do all the date calculations in php...

the downside to this is that you'd have to convert all the date information
from mysql to a human readable format...

thoughts/comments/etc...

-bruce


-Original Message-
From: John Nichel [mailto:[EMAIL PROTECTED]
Sent: Monday, September 26, 2005 11:48 AM
To: php-general@lists.php.net
Subject: Re: [PHP] mysql/php date functions..


bruce wrote:
> john...
>
> that appears to be it!! although i would have assumes it would have done a
> most significant bit fill with 0's...
>
> so my question also comes down to .. do i use the php date functions for
> date/time manipulation.. or do i use the mysql functions
>
> any thoughts/suggestions...
>
> -bruce

Personal preference I guess.  Me, I use UNIX timestamps.

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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

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

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



RE: [PHP] mysql/php date functions..

2005-09-26 Thread bruce
so you play with the time/date vars on the php side, and then simply store
them in the mysql tbl as a int(10)... or do you actually store the vars in
the mysql timestamp...

and then use the mysql date/time functions...

ie. how would you do the following...

 get a date (date1)
 get a date (date2)
 store the date1/time in mysql
 add the date1 + date2 and store the result in mysql
 read the result from mysql, with the result being in the year/month/date
format

--

or,

would you just get the unix_timestamp representation of the dates, and store
the 10 int formats in the mysql tbl. you could then extract/select the date
information from the tbls, and do all the date calculations in php...

the downside to this is that you'd have to convert all the date information
from mysql to a human readable format...

thoughts/comments/etc...

-bruce


-Original Message-
From: John Nichel [mailto:[EMAIL PROTECTED]
Sent: Monday, September 26, 2005 11:48 AM
To: php-general@lists.php.net
Subject: Re: [PHP] mysql/php date functions..


bruce wrote:
> john...
>
> that appears to be it!! although i would have assumes it would have done a
> most significant bit fill with 0's...
>
> so my question also comes down to .. do i use the php date functions for
> date/time manipulation.. or do i use the mysql functions
>
> any thoughts/suggestions...
>
> -bruce

Personal preference I guess.  Me, I use UNIX timestamps.

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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

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



RE: [PHP] mysql/php date functions..

2005-09-26 Thread Jim Moseby


> -Original Message-
> From: bruce [mailto:[EMAIL PROTECTED]
> Sent: Monday, September 26, 2005 2:46 PM
> To: 'John Nichel'; php-general@lists.php.net
> Subject: RE: [PHP] mysql/php date functions..
> 
> 
> john...
> 
> that appears to be it!! although i would have assumes it 
> would have done a
> most significant bit fill with 0's...
> 
> so my question also comes down to .. do i use the php date 
> functions for
> date/time manipulation.. or do i use the mysql functions
> 
> any thoughts/suggestions...
> 
> -bruce
> 

That depends largely on the situation.  For instance, if you want to
increment a date in a MySQL table, you would likely do it with a MySQL
statement, because to do it in PHP, you need to do a read, then add the day,
then a write, (two DB calls).  With MySQL, you would just do something like:

update `mytable` set 'columnname` date_add(columnname, interval 1 day);

One call to the DB instead of two, much more efficient.  

There are many instances where you would want to use PHP to manipulate dates
too, depending on their circumstances.

JM

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



Re: [PHP] mysql/php date functions..

2005-09-26 Thread John Nichel

bruce wrote:

john...

that appears to be it!! although i would have assumes it would have done a
most significant bit fill with 0's...

so my question also comes down to .. do i use the php date functions for
date/time manipulation.. or do i use the mysql functions

any thoughts/suggestions...

-bruce


Personal preference I guess.  Me, I use UNIX timestamps.

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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



RE: [PHP] mysql/php date functions..

2005-09-26 Thread bruce
john...

that appears to be it!! although i would have assumes it would have done a
most significant bit fill with 0's...

so my question also comes down to .. do i use the php date functions for
date/time manipulation.. or do i use the mysql functions

any thoughts/suggestions...

-bruce


-Original Message-
From: John Nichel [mailto:[EMAIL PROTECTED]
Sent: Monday, September 26, 2005 11:19 AM
To: php-general@lists.php.net
Subject: Re: [PHP] mysql/php date functions..


bruce wrote:
> thanks...
>
> but that's not it john... i'm not worried about creating the sql_statement
> in the php...
>
> i'm concerned that i can't seem to craft/create a basic sql cmd within
mysql
> to get a value (other than NOW()) to work...
>
> if i do (from mysql)
>  -->> insert into foo (id, time) values (2, 33), it doesn't work...
> if i
>  -->> insert into foo (id, time) values (2, NOW()), it works!!...
>
> my question is why???

Without knowing the structure of your table, my guess is that the column
time is expecting a valid timestamp, and 33 is not a valid MySQL
timestamp.

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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

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



RE: [PHP] mysql/php date functions..

2005-09-26 Thread bruce

but that still doesn't explain why i can't slam some value directly into the
timestamp var within the mysql tbl...


-Original Message-
From: Chris W. Parker [mailto:[EMAIL PROTECTED]
Sent: Monday, September 26, 2005 11:15 AM
To: php-general@lists.php.net
Subject: RE: [PHP] mysql/php date functions..


bruce <mailto:[EMAIL PROTECTED]>
on Monday, September 26, 2005 11:13 AM said:

> i'm concerned that i can't seem to craft/create a basic sql cmd
> within mysql to get a value (other than NOW()) to work...
[snip]
> my question is why???

MySQL timestamps are different from UNIX timestamps.


Chris.

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

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

Re: [PHP] mysql/php date functions..

2005-09-26 Thread John Nichel

bruce wrote:

thanks...

but that's not it john... i'm not worried about creating the sql_statement
in the php...

i'm concerned that i can't seem to craft/create a basic sql cmd within mysql
to get a value (other than NOW()) to work...

if i do (from mysql)
 -->> insert into foo (id, time) values (2, 33), it doesn't work...
if i
 -->> insert into foo (id, time) values (2, NOW()), it works!!...

my question is why???


Without knowing the structure of your table, my guess is that the column 
time is expecting a valid timestamp, and 33 is not a valid MySQL 
timestamp.


--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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



RE: [PHP] mysql/php date functions..

2005-09-26 Thread Chris W. Parker
bruce 
on Monday, September 26, 2005 11:13 AM said:

> i'm concerned that i can't seem to craft/create a basic sql cmd
> within mysql to get a value (other than NOW()) to work...
[snip]
> my question is why???

MySQL timestamps are different from UNIX timestamps.


Chris.

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



RE: [PHP] mysql/php date functions..

2005-09-26 Thread bruce
along the same way...

why can't i see the timestamp designation (ie the double/int) instead of the
date-time format when i look at the timestmp var when i do a 'select * from
t1' within mysql??

arrgghh!

-bruce


-Original Message-
From: John Nichel [mailto:[EMAIL PROTECTED]
Sent: Monday, September 26, 2005 11:00 AM
To: php-general@lists.php.net
Subject: Re: [PHP] mysql/php date functions..


bruce wrote:
> how can i create a mysql sql statement to insert a php 'time()' into
mysql?
>
> i've got the mysql var 't1, timestamp' but i can't figure out how to do an
> insert
>
> $q = time();
> $sql = sprintf("insert into foo (id, ctime) values(%d, %???), $id, $q);
>
> can't figure out how to get this to work...
>
> if i create a sql statement and run it directly within mysql,
>
> -->insert into foo (id, ctime) values(2, NOW());
>
> this works.. but i can't figure out how to create the sql using the php
> time() function and getting the insert from the php app...
>
> so what's the basic part i'm missing??!!
>
> -bruce

$sql = "INSERT INTO db.table ( id, ctime ) VALUES ( " . $id . ", " .
time() . " )";

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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

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



RE: [PHP] mysql/php date functions..

2005-09-26 Thread bruce
thanks...

but that's not it john... i'm not worried about creating the sql_statement
in the php...

i'm concerned that i can't seem to craft/create a basic sql cmd within mysql
to get a value (other than NOW()) to work...

if i do (from mysql)
 -->> insert into foo (id, time) values (2, 33), it doesn't work...
if i
 -->> insert into foo (id, time) values (2, NOW()), it works!!...

my question is why???

-bruce

-Original Message-
From: John Nichel [mailto:[EMAIL PROTECTED]
Sent: Monday, September 26, 2005 11:00 AM
To: php-general@lists.php.net
Subject: Re: [PHP] mysql/php date functions..


bruce wrote:
> how can i create a mysql sql statement to insert a php 'time()' into
mysql?
>
> i've got the mysql var 't1, timestamp' but i can't figure out how to do an
> insert
>
> $q = time();
> $sql = sprintf("insert into foo (id, ctime) values(%d, %???), $id, $q);
>
> can't figure out how to get this to work...
>
> if i create a sql statement and run it directly within mysql,
>
> -->insert into foo (id, ctime) values(2, NOW());
>
> this works.. but i can't figure out how to create the sql using the php
> time() function and getting the insert from the php app...
>
> so what's the basic part i'm missing??!!
>
> -bruce

$sql = "INSERT INTO db.table ( id, ctime ) VALUES ( " . $id . ", " .
time() . " )";

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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

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



Re: [PHP] mysql/php date functions..

2005-09-26 Thread John Nichel

bruce wrote:

how can i create a mysql sql statement to insert a php 'time()' into mysql?

i've got the mysql var 't1, timestamp' but i can't figure out how to do an
insert

$q = time();
$sql = sprintf("insert into foo (id, ctime) values(%d, %???), $id, $q);

can't figure out how to get this to work...

if i create a sql statement and run it directly within mysql,

-->insert into foo (id, ctime) values(2, NOW());

this works.. but i can't figure out how to create the sql using the php
time() function and getting the insert from the php app...

so what's the basic part i'm missing??!!

-bruce


$sql = "INSERT INTO db.table ( id, ctime ) VALUES ( " . $id . ", " . 
time() . " )";


--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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



RE: [PHP] mysql/php date functions..

2005-09-26 Thread bruce
how can i create a mysql sql statement to insert a php 'time()' into mysql?

i've got the mysql var 't1, timestamp' but i can't figure out how to do an
insert

$q = time();
$sql = sprintf("insert into foo (id, ctime) values(%d, %???), $id, $q);

can't figure out how to get this to work...

if i create a sql statement and run it directly within mysql,

-->insert into foo (id, ctime) values(2, NOW());

this works.. but i can't figure out how to create the sql using the php
time() function and getting the insert from the php app...

so what's the basic part i'm missing??!!

-bruce




-Original Message-
From: Silvio Porcellana [mailto:[EMAIL PROTECTED]
Sent: Monday, September 26, 2005 8:51 AM
To: php-general@lists.php.net
Subject: Re: [PHP] mysql/php date functions..


Jim Moseby wrote:
>
> Hi Bruce!
>
> MySQL and PHP both have extensive built-in date functions that are clearly
> documented and extraordinarily easy to use. For the vast majority of
> situations, there is no need to manually write any custom date-handling
> code. The decision to use MySQL or PHP to manipulate a date for a given
> instance depends largely on the particulars of that situation.
>
> For instance, if you want to increment a MySQL date column by one day, it
> would likely be better to use the MySQL date functions to do it, because
to
> use PHP, you have to read the date, manipulate it, then write it back,
> whereas if you use a SQL statement, you can do it with one DB call.
>
> See:
> http://www.php.net/datetime
> http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html
>
> Cheers!
>

Just my 0.02 euros.

When I need to use dates in PHP *and* MySQL I usually use the UNIX
timestamp (seconds since the epoch, that is, the PHP http://php.net/time
output).
This way I can (quite) easily calculate date differences etc. (usually
all the calculations are done in PHP, also when building SQL queries).

As I said, just my 0.02 euros...

Cheers
Silvio

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

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



Re: [PHP] mysql/php date functions..

2005-09-26 Thread Silvio Porcellana
Jim Moseby wrote:
> 
> Hi Bruce!
> 
> MySQL and PHP both have extensive built-in date functions that are clearly
> documented and extraordinarily easy to use. For the vast majority of
> situations, there is no need to manually write any custom date-handling
> code. The decision to use MySQL or PHP to manipulate a date for a given
> instance depends largely on the particulars of that situation.
> 
> For instance, if you want to increment a MySQL date column by one day, it
> would likely be better to use the MySQL date functions to do it, because to
> use PHP, you have to read the date, manipulate it, then write it back,
> whereas if you use a SQL statement, you can do it with one DB call.
> 
> See:
> http://www.php.net/datetime
> http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html
> 
> Cheers!
> 

Just my 0.02 euros.

When I need to use dates in PHP *and* MySQL I usually use the UNIX
timestamp (seconds since the epoch, that is, the PHP http://php.net/time
output).
This way I can (quite) easily calculate date differences etc. (usually
all the calculations are done in PHP, also when building SQL queries).

As I said, just my 0.02 euros...

Cheers
Silvio

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



RE: [PHP] mysql/php date functions..

2005-09-26 Thread Jim Moseby
> -Original Message-
> From: bruce [mailto:[EMAIL PROTECTED]
> Sent: Monday, September 26, 2005 11:12 AM
> To: php-general@lists.php.net
> Subject: [PHP] mysql/php date functions..
> 
> 
> hi...
> 
> can anybody point me to a good/basic tutorial (tested) for 
> php/mysql date
> functions... basically, i want to store a date/time in a 
> column, and be able
> to read it, manipulate it, and update the table. i've seen various
> articles/sample code, but i'm looking for something that i 
> cna pretty much
> rewrite and use without having to do a lot of initial testing..
> 
> if i create the functions myself, i'm going to need to do 
> initial testing to
> make sure i haven't screwed something up, and i'm on a time crunch!!
> 

Hi Bruce!

MySQL and PHP both have extensive built-in date functions that are clearly
documented and extraordinarily easy to use. For the vast majority of
situations, there is no need to manually write any custom date-handling
code. The decision to use MySQL or PHP to manipulate a date for a given
instance depends largely on the particulars of that situation.

For instance, if you want to increment a MySQL date column by one day, it
would likely be better to use the MySQL date functions to do it, because to
use PHP, you have to read the date, manipulate it, then write it back,
whereas if you use a SQL statement, you can do it with one DB call.

See:
http://www.php.net/datetime
http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html

Cheers!

JM

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



[PHP] mysql/php date functions..

2005-09-26 Thread bruce
hi...

can anybody point me to a good/basic tutorial (tested) for php/mysql date
functions... basically, i want to store a date/time in a column, and be able
to read it, manipulate it, and update the table. i've seen various
articles/sample code, but i'm looking for something that i cna pretty much
rewrite and use without having to do a lot of initial testing..

if i create the functions myself, i'm going to need to do initial testing to
make sure i haven't screwed something up, and i'm on a time crunch!!

thanks

-bruce
[EMAIL PROTECTED]

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



Re: [PHP] date functions

2004-02-24 Thread Adam Bregenzer
On Tue, 2004-02-24 at 13:29, Matthew Oatham wrote:
> You might already be fed up with my posts but I'm a complete PHP
> newbie and find these groups are the best way to learn! Anyway I have
> the database date in the format: -mm-dd hh:mm:ss e.g. 2004-02-24
> 07:57:59 but when in some situations I only want to show the user the
> date in the format dd-mm- what is the correct / best php function
> to use for this purpose ?

You can either use the date functions or regexps, I would recommend the
date functions, they may be a bit slower but they are more flexible and
easier to read:
$timestamp = strtotime('2004-02-24 07:57:59');
$date = date('d-m-Y', $timestamp);

Also, it would be best to try and get the date in a timestamp instead of
a formatted string, check if your database can do this.  If so then you
can skip the strtotime step above.  If you are using MySQL and the date
field is one of the date formats (ie. not char/varchar) take a look at
MySQL's date formatting functions[1].

Regards,
Adam

[1] http://www.mysql.com/doc/en/Date_and_time_functions.html

-- 
Adam Bregenzer
[EMAIL PROTECTED]
http://adam.bregenzer.net/

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



RE: [PHP] date functions

2004-02-24 Thread Sam Masiello

Depending on your database engine (which you didn't mention in your
post), some allow you to format the date however you want it as you pull
it out of the database in your sql query.  I always find this to be the
easiest way to do it.  That way you don't have to worry about formatting
the data after it has been output from your query.

HTH!

--Sam



Matthew Oatham wrote:
> Hi,
> 
> You might already be fed up with my posts but I'm a complete PHP
> newbie and find these groups are the best way to learn! Anyway I have
> the database date in the format: -mm-dd hh:mm:ss e.g. 2004-02-24
> 07:57:59 but when in some situations I only want to show the user the
> date in the format dd-mm- what is the correct / best php function
> to use for this purpose ? 
> 
> Cheers.
> 
> Matt

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



RE: [PHP] date functions

2004-02-24 Thread Pablo Gosse

You might already be fed up with my posts but I'm a complete PHP newbie
and find these groups are the best way to learn! Anyway I have the
database date in the format: -mm-dd hh:mm:ss e.g. 2004-02-24
07:57:59 but when in some situations I only want to show the user the
date in the format dd-mm- what is the correct / best php function to
use for this purpose ?


strtotime() in conjunction with date()

http://ca2.php.net/manual/en/ref.datetime.php

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



[PHP] date functions

2004-02-24 Thread Matthew Oatham
Hi,

You might already be fed up with my posts but I'm a complete PHP newbie and find these 
groups are the best way to learn! Anyway I have the database date in the format: 
-mm-dd hh:mm:ss e.g. 2004-02-24 07:57:59 but when in some situations I only want 
to show the user the date in the format dd-mm- what is the correct / best php 
function to use for this purpose ?

Cheers.

Matt

Fw: [PHP] date functions

2002-09-23 Thread Kevin Stone

You should be working with UNIX timestamps here.  Convert the dates to human
readble only after you've done the calcuations.
-Kevin


- Original Message -
From: "Patrick" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, September 23, 2002 2:38 PM
Subject: [PHP] date functions


> i got 2 dates and i want to know how many minutes between em,, like:
>
> $date1 = date("Y-m-j H:i");
> $date2 = date("Y-m-j H:i", strtotime("now") + 1800);
>
> $minutes = date_something($date1, $date2);
>
> echo "there are $minutes between, $date1 and $date2";
>
> regards
> patrick
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


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




Re: [PHP] date functions

2002-09-23 Thread Support @ Fourthrealm.com

Patrick

Off the top of my head... Convert both date1 and date2 to unix timestamps, 
and subtract one from the other.  That will give you the number of seconds 
between them.  Then, convert to hours, minutes, etc as required.

Peter


At 10:38 PM 9/23/2002 +0200, Patrick wrote:
>i got 2 dates and i want to know how many minutes between em,, like:
>
>$date1 = date("Y-m-j H:i");
>$date2 = date("Y-m-j H:i", strtotime("now") + 1800);
>
>$minutes = date_something($date1, $date2);
>
>echo "there are $minutes between, $date1 and $date2";
>
>regards
>patrick
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

- - - - - - - - - - - - - - - - - - - - -
Fourth Realm Solutions
[EMAIL PROTECTED]
http://www.fourthrealm.com
Tel: 519-739-1652
- - - - - - - - - - - - - - - - - - - - -


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




[PHP] date functions

2002-09-23 Thread Patrick

i got 2 dates and i want to know how many minutes between em,, like:

$date1 = date("Y-m-j H:i");
$date2 = date("Y-m-j H:i", strtotime("now") + 1800);

$minutes = date_something($date1, $date2);

echo "there are $minutes between, $date1 and $date2";

regards
patrick



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




[PHP] Date functions & Unic Epoch

2002-06-09 Thread Juan Antonio Ruiz Zwollo

Hi!

Say, has anybody re-written the date funtions so they work with any date and
not be crippled by the unix timestamp range limit?

I am looking for a function which will do the equivalent of
   date("w",mktime(0,0,0,8,30,1934))
but that will actually *work*.

Does anybody know a way to return which day of the week (0-7) it is for
dates outside the unix timestamp range?

I wish this stuff would be build into PHP.

Saludos,


Juan Antonio Ruiz Zwollo






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




Re: [PHP] date functions

2002-05-18 Thread Miguel Cruz

On Sun, 19 May 2002, Josh Edwards wrote:
> Does anyone know  a good way to count the days between two dates. ie how
> many Mondays fall between two dates. As a starting  point I have calculated
> the start and end dates and the no of days b/w them.

Pretty much common sense, right? How about something like this:

  // $timestamp1 = starting date (unix timestamp)
  // $timestamp2 = ending date (unix timestamp)
  // $weekday = day we're counting (0 = Sunday, 1 = Monday, etc.)
  function weekdaysBetween ($timestamp1, $timestamp2, $weekday)
  {
return floor(intval(($timestamp2 - $timestamp1) / 86400) / 7)
  + ((date('w', $timestamp1) <= $weekday) ? 1 : 0);
  }

miguel


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




Re: [PHP] date functions

2002-05-18 Thread Tom Rogers

Hi
I think this works :)

";
else:
 echo "there are no Mondays between $date1 and $date2 ";
endif;
?>
Tom



At 10:22 AM 19/05/2002, Josh Edwards wrote:
>Does anyone know  a good way to count the days between two dates. ie how
>many Mondays fall between two dates. As a starting  point I have calculated
>the start and end dates and the no of days b/w them.
>
>
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php


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




Re: [PHP] date functions

2002-05-18 Thread Richard Baskett

Well you could do two str2time() calls like this:

# Two Dates to Compare #
$date1 = strtotime("Oct 18, 2002");
$date2 = strtotime("Jan 18, 2002");

# Assign the earliest date and laterdate to variables #
$earlyDate = ($date1 < $date2) ? $date1 : $date2;
$laterDate = ($earlyDate == $date1) ? $date2 : $date1;

# Computes to find how many days are between the two dates #
$daysBetween = ceil(($laterDate - $earlyDate)/(60*60*24));
echo $daysBetween;

There's probably an easier way of doing this, but hey it works! ;)

Rick

You will never be happy if you continue to search for what happiness
consists of. You will never live if you are looking for the meaning of life.
- Albert Camus

> From: "Josh Edwards" <[EMAIL PROTECTED]>
> Date: Sun, 19 May 2002 10:22:28 +1000
> To: [EMAIL PROTECTED]
> Subject: [PHP] date functions
> 
> Does anyone know  a good way to count the days between two dates. ie how
> many Mondays fall between two dates. As a starting  point I have calculated
> the start and end dates and the no of days b/w them.
> 
> 
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


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




[PHP] date functions

2002-05-18 Thread Josh Edwards

Does anyone know  a good way to count the days between two dates. ie how
many Mondays fall between two dates. As a starting  point I have calculated
the start and end dates and the no of days b/w them.





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




Re: [PHP] Date Functions

2001-08-20 Thread Renze Munnik

On Mon, Aug 20, 2001 at 12:12:15PM +0100, Peter Allum wrote:
> I am using PHP 4, I have a date which I am adding to a MYSQL db, I have that
> bit sorted, I am trying to calculate an 2 expiry dates, one that is 1 year
> and 11 months ahead of the 1st date and another that is 2 years ahead of the
> 1st date.
>
> Any Ideas, I have seen lots of scripts for adding days but not months or
> years.
> Thank you in advance for your reply


Peter,

For the first date:
-
  $month = date("m") + 11;
  $day = date("d");
  $year = date("Y") + 1;
  $newDate = date("Y-m-d",mktime(0,0,0,$month,$day,$year));

or

  $newDate = date("Y-m-d",mktime(0,0,0,date("m")+11,date("d"),date("Y")+1));
-

And for the second date:
-
  $month = date("m") + 11;
  $day = date("d");
  $year = date("Y") + 3;
  $newDate = date("Y-m-d",mktime(0,0,0,$month,$day,$year));

or

  $newDate = date("Y-m-d",mktime(0,0,0,date("m")+11,date("d"),date("Y")+3));
-

And that's all you need!


--
* R&zE:

-- 
-- Renze Munnik
-- DataLink BV
--
-- E: [EMAIL PROTECTED]
-- W: +31 23 5326162
-- F: +31 23 5322144
-- M: +31 6 21811143
--
-- Stationsplein 82
-- 2011 LM  HAARLEM
--
-- http://www.datalink.nl
-- 

-- 
PHP General 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] Date Functions

2001-08-20 Thread Peter Allum

I am using PHP 4, I have a date which I am adding to a MYSQL db, I have that
bit sorted, I am trying to calculate an 2 expiry dates, one that is 1 year
and 11 months ahead of the 1st date and another that is 2 years ahead of the
1st date.

Any Ideas, I have seen lots of scripts for adding days but not months or
years.
Thank you in advance for your reply



-- 
PHP General 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]