Read Date From Excel OR CSV Sheet

Read Date From Excel OR CSV Sheet

When we insert datas from excel or csv to database, Date value will not insert properly. It will get error or add wrong data into database. When we fetch the date values from excel sheet, It will be change to number of days count between 1900 to date of excel shet[“string format”]. Now we have to convert this from days to current date. Using following function we change change it to date format.

<?php
/** read from excel sheet **/
$date=$objWorksheet->getCellByColumnAndRow(0, $row)->getValue();
/** OR **/
/** Use your format to get date value from excel **/
$date=$Getdatefromexcelsheet;
$date=$this->get_date_from_excel($date);
$date=date("Y-m-d",$date);   
echo $date;


    function get_date_from_excel( $poop ){
		return mktime( 0 , 0 , 0 , 1 , (int) $poop + 1, 1900 );
	}    

?>