I have searched the forum and reviewed responses to questions related to mysql date format. However, none of these responses seem to solve my problem and therefore need put it forward hoping that someone could help.
I have set up my mysql database and populating the tables using import command to import data from text files. The date from the text file is in the form "190810" i.e d.m.y. After populating my tables I realised that the mysql is truncating the date entry and producing extraordinary dates upto year 2013, 2021 and so on in in its default format. I thought mysql could reverse the date as in changing 190810 to 2010-08-19.
I am aware if you are retrieving data you can display the date as you want it. I am not retrieving data in this case but storing data from a text file which has date that must not be truncated.
So how do I import this data from the text file and maintaining the correctness of the date even if it is in mysql default format. Is there no other way I can achieve this. I am completely run out of ideas. Please advise.
Thanks for the reply and i wont start new threads on the same issue. The suggestions i have got are not working. please can people who are experts in mysql and php tell me something that is workable? I cant figure this out myself.
i have massive data in textfiles with dates in dmy format, i need to import it into mysql while preserving the correctness of the date. I am out of ideas please help.
Somebody please help!!!!
One person has prosposed the use of str_date_function and creating a duplicate table and then inserting. It is not working though.
I am not retrieving data from my database but storing from text files. How can I preserve the correctness of the date while storing it in mysql date default format. The date is getting truncated. please assist my good friends.
The format I have from the text file am importing from is this 070610, 070610. I want to preserve this correctness. It could be 2010-06-07 which is ok in mysql. Thanks in advance.
this is exactly what the STR_TO_DATE function is for
this -- 'handover_date' -- is a string
this -- handover_date -- is a column
can you see the difference?
Ok, I'll say it again:
change the str_to_date in your query to this:
str_to_date(handover_date, [B]<font color='"Red"'>'%d%m%y'</font>[/B])
I ran the following query:
insert into handover2(time, date) SELECT time, str_to_date('handover_date', '%y,%m,%d') FROM handover;
and got this output: 0000.00.00
it is not changing the format and that is where i am hooked now no progress. I appreciate your assistance
Guido thanks very much. It worked. I remain grateful.
I just gave you another suggestion. Did you try it? What is the result? And don't say: it didn't work. Explain what the exact result is.
And by the way, someone more expert in MySQL than r937 will be hard to find
Since your date is in the format 'ddmmyy' try
And don't start a new thread with the same question!
By the way, don't call your columns date and time, these are reserved words in MySQL. Of course, you might put backticks around them, but that's kind of annoying (IMO ).
please check for me what am doing wrong below is my insert stm and is entering date as 0000-00-00 . i used the following insert statement.
insert into handover2(time, date) SELECT time, str_to_date('date', '%y,%m,%d') FROM handover; thanks
Many thanks. I would try that out now.
okay, import your data into a holding table where the date is a simple varchar
then do an INSERT SELECT to copy the data into your target table from the holding table, using the STR_TO_DATE function in the SELECT part
am using phpmyadmin to import the files as csv though it can still import as txt. and below is the format of the data am importing. i.e time and date separated by commas
okay, that was the next step... how exactly are you importing it? with the LOAD DATA command?
The above the syntax. Please remember am importing date data from a text file into mysql and not retrieving.
do me a favour, go grab the syntax from the manual and post it here -- just the syntax, not the explanation
Thanks for the response. Since am populating my tables via import from text files, how can this function be utilized?