DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   csv, convert date, mysql, php (http://www.daniweb.com/forums/thread101470.html)

budiman Dec 17th, 2007 9:35 am
csv, convert date, mysql, php
 
HI

I want to submit csv file data into mysql using php.
One of the fields contain data : date with format (dd-mm-yyy).
I want to store the data in mysql with date format (yyy-mm-dd).
pls tell me how 2 do.
pls help me
Thanks.
bye

scru Dec 17th, 2007 9:44 am
Re: csv, convert date, mysql, php
 
First you calculate a timestamp integer from the old date (that is the number of seconds from January 1, 1970 00:00:00 GMT to the old date).

Then you call the php function date() with a format string and pass in the timestamp. Like so:
$datestring = date("Y-m-d", $timestamp);

See here for more information on using date format strings.

nav33n Dec 17th, 2007 10:07 am
Re: csv, convert date, mysql, php
 
First, you fetch the data from the csv file using fgetcsv. Its returns the value as an array. Access the array element where the date is stored and do as scru has mentioned.


All times are GMT -4. The time now is 12:25 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC