Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/246781-datetime-in-excel-csv-field/
Share on other sites

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 :)

 

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.