Divante Posted September 9, 2011 Share Posted September 9, 2011 Hi, basically i am parsing some rtf/word files and generating excel csv's for upload into mysql database....my issue is in one of the fields i want to store the value in the mysql datetime / date format but excel keeps reformating it. Any help on how to overcome this will be highly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/246781-datetime-in-excel-csv-field/ Share on other sites More sharing options...
gristoi Posted September 9, 2011 Share Posted September 9, 2011 leave the excel date format as it is and use the date conversion power in mysql to alter the date to a timestamp on insert: let say for example you had it showing in the excel sheet as 01/10/2011 00:01:01, then you would do this on the insert: $date = '01/10/2011 00:01:01'; INSERT INTO tbl (`datecolumn`) values (STR_TO_DATE($date,'%d/%m/%Y $h:%i:%s')) you basically use the string to date function in mysql. the left hand part of the argument is the date you are passing in and the right hand part telss it what format the date is in. Mysql will do the rest from there and convert it into a datetime / date for you Quote Link to comment https://forums.phpfreaks.com/topic/246781-datetime-in-excel-csv-field/#findComment-1267327 Share on other sites More sharing options...
Adam Posted September 9, 2011 Share Posted September 9, 2011 CSV isn't Excel specific, essentially it's just a plain-text file. Excel is reformatting the date according to your preference when you open it... Just don't open it in Excel before you import it into the database. Quote Link to comment https://forums.phpfreaks.com/topic/246781-datetime-in-excel-csv-field/#findComment-1267328 Share on other sites More sharing options...
Divante Posted September 9, 2011 Author Share Posted September 9, 2011 thanks alot i appreciate the quick responses...thats why i love this forum Quote Link to comment https://forums.phpfreaks.com/topic/246781-datetime-in-excel-csv-field/#findComment-1267425 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.