Jump to content
Killersites Forums

Date transforms 0000-00-00 to 01-01-1970 please help to fix it


cool
 Share

Recommended Posts

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

Link to comment
Share on other sites

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']));
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...