![]() |
|
#1
|
|||
|
|||
How to replace UNIX timestamp with mysql timestampI inherited a database that has a table of registration dates in unix format, for example 1200590610
, I want to change these dates to mysql timestamp format and insert them into a new table. I have a PHP script that does the conversion <?php $intime = (1200590610); $read_in = date("Y-m-d H:i:s", $intime); ?> The original table (members) has 3 fields: fn, ln, reg_date. reg_date is in unix format. I want to select the record, convert the date and insert it into a new table (mem) with the same 3 fields. Can you help? |
|
#2
|
|||
|
|||
Re: How to replace UNIX timestamp with mysql timestampQuote:
So: Use a php loop that calls mysql_query() to go through the rows of the first table. For each row, use mysql_query() to insert column 0 and column 1 and the newly formatted date into the second table. In the following example, i just used FROM_UNIXTIME in its default format. You could use your function (or look at the formatting options of FROM_UNIXTIME, if you prefer to stick with something standard). PHP Code:
The output was something like the following for a little data base with some file information (name, owner, timestamp). (I'm kind of new at this, so I used some extra intermediate variables so that i can print out debugging results.) I didn't actually make a new table (I wanted to save some of the fun for later); I just wanted to see how to go through the rows of the first table. Code:
Regards, Dave Last edited by davekw7x : 28-Jan-2008 at 19:45.
|
|
#3
|
|||
|
|||
Re: How to replace UNIX timestamp with mysql timestampThanks Dave, I really appreciate your response. I also found a way to do it with a query that I ran against the table I wanted to convert from. Here's what I used:
INSERT INTO new date(member_id,user_id,member_number, fn, joined,renewed,expires) SELECT member_id, user_id, member_number, fn, FROM_UNIXTIME(joined), FROM_UNIXTIME(renewed), FROM_UNIXTIME(expires) FROM old_date; |
|
#4
|
|||
|
|||
Re: How to replace UNIX timestamp with mysql timestampQuote:
Boiling it down to one elegant statement is something that I (usually) leave to others (power users) so that they can make their results meet their needs. I appreciate seeing your approach. Regards, Dave |
Recent GIDBlog
A Week in Kuwait by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| combining localtime() members into a single long long | Howard_L | C Programming Language | 10 | 11-May-2007 22:58 |
| Moving data from MySQL to MySQL | meurer | MySQL / PHP Forum | 0 | 25-Jan-2007 09:03 |
| Cpanel downgrade MYSQL 4.1.X to MySQL 4.0.xx | Webhosting-live | Web Hosting Forum | 1 | 01-Sep-2006 02:54 |
| Windows: From only £20p/y,Linux: from $10p/m. ASP, ASP.NET, PHP, Free MySQL, +More | EyotaHosts | Web Hosting Advertisements & Offers | 0 | 28-Jun-2003 13:54 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The