Jump to content

Recommended Posts

Hi,

 

Im in the process of changing the software my social networking site runs off and im currently trying to pull the data from the old database and load it into the new one. 

 

The part im stuck with is the dates as they are stored differently in both databases. Heres the old and the new structures :

 

OLD

 

field : account_created

type: varchar

example : 24th Dec 2009 at 13.19

 

NEW

 

field : joindate

type : int(10)

example : 1246980713

 

Id like to pull the dates from the old database, convert them and then load them into the new one using SELECT etc. its just the conversion part im stuck with :(

 

I also have a similar problem with the d.o.b fields :

 

OLD

 

field : birth_day

type : (int11)

example : 24

 

field : birth_month

type : (int11)

example : 6

 

field : birth_year

type : (int11)

example : 1980

 

NEW

 

field : birthday

type : char(10)

example : 05-21-1978

 

Hope that makes and I hope someone can help.

 

Thanks very much.

 

Scott

Have a look at: http://us2.php.net/mktime ... should be what you need for the date conversion from readable to timestamp.

 

Now the DOB will probably have to be done by using a LEFT JOIN to select the values than concatenate them into one string and insert them.

do you know how to do basic database interaction with php? Like, pulling data from the old table?

 

yep but thats about all i know, this is what ive been doing :

 

 

<?php 
include("include/configvb.inc.php");

$users = mysql_query("SELECT * FROM joovili_users");
						  

			while ($got_users = mysql_fetch_array($users)){

mysql_query("INSERT INTO user (`userid`, `password`, `username`, `email`) 
VALUES ('".$got_users['id']."', '".$got_users['password']."', 
'".$got_users['username']."','".$got_users['email']."')");

}

$dateValueFromOldDatabase = '24th Dec 2009 at 13.19';

 

$dateAndTime = explode(' at ', $dateValueFromOldDatabase);

 

$newDatabaseDateFormat = mktime(15, 19, 0, 12, 24, 2009);

 

If you remove the 'at' strtotime will convert it, so you can do

 

$string = "24th Dec 2009 at 13.19";
$string = str_replace('at','',$string);
$timestamp =  strtotime($string);

Thanks peeps, so for the first part id do something like this ??

 

<?php 
include("include/configvb.inc.php");

$users = mysql_query("SELECT * FROM joovili_users");
						  

			while ($got_users = mysql_fetch_array($users)){


$string = $got_users['account_created'];
$string = str_replace('at','',$string);
$timestamp =  strtotime($string);


mysql_query("INSERT INTO user (`userid`, `password`, `username`, `email`, `joindate`) 
VALUES ('".$got_users['id']."', '".$got_users['password']."', 
'".$got_users['username']."','".$got_users['email']."','".$timestamp."')");

}
?>

CV,

 

I think the 'at' is part of his database value which is why I went the way I did, so you could explode it prior to fleshing out the timestamp.

 

Right. But when you explode at the "at" you are left with a 2 element array. One with '24th Dec 2009' and one with '13.19' well you turn around and use mktime with those individual number separated (and even converted, like Dec->12) well you sort of skipped the steps involved in having to go from your explode to your mktime... with what I posted, I start out with the string from the old table just the same.  I then remove the 'at' and strtotime it, which does all that stuff you skipped in your code, plus what mktime does.

 

OR die(mysql_error());

 

will spit out the error mysql generates if there is a problem with executing the query.  Use it for debugging.  Remove it when done.  Although this sounds like a one-time-use script anyways, so whatever.

 

damn i wish i knew that before lol, cheers :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.