Re: mysql/php date functions..
| From: | Kristen G. Thorson | Date: | Mon, 26 Sep 2005 20:18:59 +0000 |
| Subject: | Re: mysql/php date functions.. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-223235@lists.php.net to get a copy of this message | ||
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:bedouglas@earthlink.net] 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:john@kegworks.com] 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... -brucePersonal preference I guess. Me, I use UNIX timestamps. -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 john@kegworks.com -- 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