Jump to content

importing to Table.. how to take out / 's off dates


Recommended Posts

I need to take 12/07/2008  in the date column... importing to table and make it 12072008

 

trying to figure the substring useage for this in a ...

 

SELECT DISTINCT  MIN( substring (stripslashes (date) ) ) as date

 

that was an attempt lol not much of a good one. ive tried several all night.. its now 7am I can figure it out.

 

The select distinct min(date) as date .... wont work cause the dates not a stamp on the table but a 12/07/2008.

 

what im doing is going from one table to a temp table.. and trying to figure out how to strip the /'s off the dates  in the date  column on the fly.. before it goes into the temp table.

 

is it possible thanks?

I am using that.. but also with distinct.. and MIN or MAX.. not sure if I completely understand DISTINCT or not..

 

heres an example.. I want or group by manufacturer... and have the most current date shown

 

but distinct by dates.. which the dates come in from a csv file as text.. then converted how I show it below.. it does convert and the column is entrydate, which is set in sql to DATE

 

$sql = "INSERT INTO TMP SELECT DISTINCT  Bike_manufacture, MAX(STR_TO_DATE(entrydate, '%m/%d/%Y')) as entrydate, blah, blah_blah, bleh_bleh_bleh from STREETB group by (Bike_manufacture)";

mysql_query($sql); 

 

it converts the date coming in as 08/08/2008  to 2008-08-08  fine..

But the MIN or MAX is only grabbing the lower of the two Bike_manufacture's that are the same cept for the changes in the newer entry...

 

like yamaha 2008-08-08

and yamaha 2008-10-10

 

it grabs 2008-08-08  everytime..

 

is it cause sql is not converting the date properly into the Table so sql is grabbing the older one all the time?

 

 

 

MAX(STR_TO_DATE(entrydate, '%m/%d/%Y'))  

 

 

cant the above be used on the fly when transfering into the TMP table?

 

to anyone who can help.. its now a 3 week trial and error tedious process.

 

thanks to anyone who can suggest anything to move me on from being stuck this long lol.

IF I made a 2nd tmp table..  so now I have.. cvs into first table... then converts dates in the first TMP table..  then the 2 TMP table have MIN MAX sort the dates..

 

what would I put for this to work... without the MIN MAX... cause when I just drop the min or max.. I get NULL dates. But with the MIN (or max) it actually converts the dates.

 

????

 

$sql = "INSERT INTO TMP SELECT DISTINCT  Bike_manufacture, (STR_TO_DATE(entrydate, '%m/%d/%Y')) as entrydate, blah, blah_blah, bleh_bleh_bleh from STREETB group by (Bike_manufacture)";

mysql_query($sql); 

 

any ideas? drop the brackets? or is there code im missing now?? since I took the min or max out on the FIRST TEMP table. ??

 

thanks.

 

 

 

 

The thing... converts perfectly.. and does min max properly.. but when new data is imported with the already converted dates.. the system looks at the first one that does not need to be converted and stops.

 

2008-10-08

09/10/2008

etc

etc

 

it stops and does not convert the newer dates added in the other rows.

 

anyone run into this problem?? how to make it ignore already converted formats.. and skip down the list to non converted and convert them?

Start over..

 

have two tables .. ones full of data.. and the other empty..

 

I want to move all from TABLE_A to TABLE_B..  while converting a text date to real DATE..

 

my guess...

 

$sql = "INSERT INTO TABLE_B SELECT col1, (STR_TO_DATE(col2, '%m/%d/%Y')) as col2, col3,col4,col5,col6 from TABLE_A ";

 

this does not work for me.. and the date does not convert.

 

see any errors?

WOW fenway  .... havent figured it out yet.. but now im really understanding whats DISTINCT AND GROUP BY AND MAX means..

 

all I wants to do was grab the two line identical but with different dates.. and make it grab the newer full line with the newer date.

 

I did not realize what I was doing is using something that pulls a max date.. and meshes it in with an older line.. making a whole new line.. no wonder I was so completely screwed up!!!!!!!!

 

ok so this is what I want to do..

 

yamaha | todays date      | red | 600cc | fast | 25 sold

yamaha | yesterdays date | red | 600cc | fast | 10 sold

 

Kawasaki | yesterdays date | red | 600cc | fast | 14 sold

 

so it would use the new yamaha coming in from the cvs file...

and would just re add  kawasaki cause theirs no change.

And kick out the old yamaha with the old sold qty.

 

What it was doing and confused me was...  took todays date but still posted yesterdays only 10 sold...

 

like so.

 

yamaha | todays date | red | 600cc | fast | 10 sold

 

didnt realize it meshed the lines together and only took the MAX date and put it in yesterdays entry.

 

wow .. duh!

 

ok so.. all I want to do is... get the new listing in the db.. and kick out the out listing by date.

but also keep any non changed entries regardless of date.

 

 

 

 

 

Learning about indexing now.. seems like that is what I really need.

 

find an index and delete the rows with older dates.

 

hey im learning self teaching can be long and grueling by it should be oh about 2054 when ive learn 1/5th of php. lol

I think I understand now... if you have a unique index on your destination table, then an INSERT INTO... ON DUPLICATE KEY UPDATE... will allow you "overwrite" all the entires.  Of course, you'll have to use a derived table to get the most recent first.

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.