webmaster1 Posted April 19, 2010 Share Posted April 19, 2010 I'm importing an excel file into a table for outputting into a php page. In excel, my date reads: 4/19/2010 If the destined field is set as datetime, will PHP/MySql be able to recognize it as date? Link to comment https://forums.phpfreaks.com/topic/198969-importing-dates-from-excel-to-mysql-to-php/ Share on other sites More sharing options...
Ken2k7 Posted April 19, 2010 Share Posted April 19, 2010 Please read this - http://dev.mysql.com/doc/refman/5.0/en/datetime.html Link to comment https://forums.phpfreaks.com/topic/198969-importing-dates-from-excel-to-mysql-to-php/#findComment-1044399 Share on other sites More sharing options...
dotMoe Posted April 19, 2010 Share Posted April 19, 2010 If you email me tomorrow; I have a function at the office that converts it from "excel" time, to a timestamp if you want. Link to comment https://forums.phpfreaks.com/topic/198969-importing-dates-from-excel-to-mysql-to-php/#findComment-1044445 Share on other sites More sharing options...
webmaster1 Posted April 19, 2010 Author Share Posted April 19, 2010 If you email me tomorrow; I have a function at the office that converts it from "excel" time, to a timestamp if you want. Sent you a PM. Link to comment https://forums.phpfreaks.com/topic/198969-importing-dates-from-excel-to-mysql-to-php/#findComment-1044478 Share on other sites More sharing options...
webmaster1 Posted April 19, 2010 Author Share Posted April 19, 2010 Please read this - http://dev.mysql.com/doc/refman/5.0/en/datetime.html Have done. I've just tried inserting YYYY/MM/DD and YYYY/DD/MM into a timedate field but I'm just ending up with zeros. Link to comment https://forums.phpfreaks.com/topic/198969-importing-dates-from-excel-to-mysql-to-php/#findComment-1044482 Share on other sites More sharing options...
webmaster1 Posted April 19, 2010 Author Share Posted April 19, 2010 Formatted date in excel to match YYYY-MM-DD HH:MM:SS. Working fine now. I was hoping MySql would have been able to pick up on a variety of formats for datetime field inserts. Link to comment https://forums.phpfreaks.com/topic/198969-importing-dates-from-excel-to-mysql-to-php/#findComment-1044486 Share on other sites More sharing options...
PFMaBiSmAd Posted April 19, 2010 Share Posted April 19, 2010 The mysql STR_TO_DATE() function can produce a DATETIME value from any other data/time format. Your use of YYYY/MM/DD should have worked, depending on if the MM/DD had leading zero's and what your code actually was doing. Link to comment https://forums.phpfreaks.com/topic/198969-importing-dates-from-excel-to-mysql-to-php/#findComment-1044487 Share on other sites More sharing options...
webmaster1 Posted April 19, 2010 Author Share Posted April 19, 2010 Thanks for that function. I was just using a regular insert but no, I did not have preceding zeros for day/month. Link to comment https://forums.phpfreaks.com/topic/198969-importing-dates-from-excel-to-mysql-to-php/#findComment-1044490 Share on other sites More sharing options...
webmaster1 Posted April 19, 2010 Author Share Posted April 19, 2010 I've imported the csv file using import on phpmyadmin but the dates are showing in zero's. Despite formating the dates correctly in excel, csv insists on formatting the date as 4/13/2010 12:00:00 AM. How do I correct this? Link to comment https://forums.phpfreaks.com/topic/198969-importing-dates-from-excel-to-mysql-to-php/#findComment-1044509 Share on other sites More sharing options...
webmaster1 Posted April 19, 2010 Author Share Posted April 19, 2010 Found a quirky solution: http://forums.devshed.com/mysql-help-4/import-csv-date-to-mysql-673242.html Apparently, each time the csv file is open, the format of the date is reset. In other words, once the csv file is saved from excel, it can't be opened in excel prior to uploading it. I'm just glad to find the solution. I'd never have guessing that thiswas the issue. Link to comment https://forums.phpfreaks.com/topic/198969-importing-dates-from-excel-to-mysql-to-php/#findComment-1044513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.