php - Date issue: always shows 01 Jan rather than converting to desired Date -


this question has answer here:

i new php programming , facing strange problem, through different forums able learn how convert dates of different formats our desired formats, today not possible , given 01 jan no matter gave in variable, strange working great. code following:

i using combination of date , strtotime php functions, as:

$coll_date_1[$i] = $row->coll_date_1;   //this 08-08 i.e 8 aug  $coll_date_1[$i] = date('d m',strtotime($coll_date_1[$i]));  //this return 01 jan 

the 1st line assigns value database variable, , 2nd line function convert them desired format. know doing silly mistake, cant seem pin point is...

that happens because 08-08 not valid date format.

you try adding "fake" year in front of it, 2000-08-08, or current year, 2013-08-08, , do

$coll_date_1[$i] = 'year-'.$row->coll_date_1; // "year" "2000" or current year date('d m', strtotime($coll_date_1[$i])); 

anyway, should change database handle dates in proper format, should yyyy-mm-dd, example in mysql you'd use date type field.

edit:

if cannot change database structure, have php 5.3+, can use datetime class parse date

datetime::createfromformat('m-d', $row->coll_date_1)->format('d m'); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -