i reading data excel , import them db. having strange problem. ok except date section. code section is:
$dob = $cells[$i][6]; echo $dob.'<br>'; $timestamp = strtotime($dob); echo 'time- '.$timestamp; echo 'time2- '.strtotime('01-01-2000');exit; and output is:
01-01-2000 time- time2- 946677600 the value used in excel file same 01-01-2000 can see output.
i don't understand why strtotime function can return value hardcoded string version not variable read excel file?
thanks help.
solution: in case faces same problem how handled it.
$dob_temp = $cells[$i][6]; $dob_numbers = preg_replace("/[^0-9]/","",$dob_temp); $timestamp = strtotime(substr($dob_numbers,0,2).'-'.substr($dob_numbers,2,2).'-'.substr($dob_numbers,4,4)); $dob = date('y-m-d', $timestamp);
it's string retrieve excel file has odd characters - example dash rather hyphen trips strtotime.
example:
<?php $dob = '01―01―2000'; echo $dob.'<br>'; $timestamp = strtotime($dob); echo 'time- '.$timestamp; echo 'time2- '.strtotime('01-01-2000');exit; you may want clean dates coming file or use datetime::createfromformat pass format matches contents of string.
Comments
Post a Comment