cool Posted December 24, 2011 Report Share Posted December 24, 2011 column Name: secondgirld Datatype:date To echo the date in "d-m-Y" format i am using the below code echo date("d-m-Y", strtotime($row['secondgirld'])); There is no problem when secondgirld is not equal to empty (secondgirld!='') when secondgirld field is empty (that is:secondgirld=='') it stores value as 0000-00-00 in mysql. But echo date("d-m-Y", strtotime($row['secondgirld'])); shows 01-01-1970. please help to fix this problem. I just want to display a blank field or 00-00-0000 Quote Link to comment Share on other sites More sharing options...
Coreinsanity Posted December 24, 2011 Report Share Posted December 24, 2011 column Name: secondgirld Datatype:date To echo the date in "d-m-Y" format i am using the below code echo date("d-m-Y", strtotime($row['secondgirld'])); There is no problem when secondgirld is not equal to empty (secondgirld!='') when secondgirld field is empty (that is:secondgirld=='') it stores value as 0000-00-00 in mysql. But echo date("d-m-Y", strtotime($row['secondgirld'])); shows 01-01-1970. please help to fix this problem. I just want to display a blank field or 00-00-0000 strtotime returns boolean false when '0000-00-00' is passed to it. When false is provided as the second parameter in date() it returns 01-01-1970. If I were you, I would do something like: if ($row['secondgirld'] == '0000-00-00') { echo ''; } else { echo date('m-d-Y', strtotime($row['secondgirld'])); } Quote Link to comment Share on other sites More sharing options...
cool Posted December 24, 2011 Author Report Share Posted December 24, 2011 strtotime returns boolean false when '0000-00-00' is passed to it. When false is provided as the second parameter in date() it returns 01-01-1970. If I were you, I would do something like: if ($row['secondgirld'] == '0000-00-00') { echo ''; } else { echo date('m-d-Y', strtotime($row['secondgirld'])); } Another one: DATE_FORMAT(`secondgirld`,'%d-%m-%Y') AS secondgirld Quote Link to comment Share on other sites More sharing options...
Coreinsanity Posted December 25, 2011 Report Share Posted December 25, 2011 Another one: DATE_FORMAT(`secondgirld`,'%d-%m-%Y') AS secondgirld Not quite sure what you're wanting/saying? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.