Skip navigation
Currently Being Moderated

Problem with update form and date (show 1970-01-01)

Mar 22, 2013 5:02 AM

Tags: #php #date #1970-01-01

Hi, I've a update form (php/mysql) with many date input field. When my date is 000-00-00 I show 1970-01-01. Why??

 

This is the code:

 

label for="data_chiusura"><strong>Data chiusura</strong></label>

      <input type="text" name="Data_chiusura" value="<?php echo $string=$row_Recordset1['data_chiusura'];

    if($string == '0000-00-00'){

    $string = '';

    } else {

    $string = date("d-m-Y", strtotime($string));

    }; ?>" id="Data_chiusura">

 

Thanks

 

k

 
Replies
  • Currently Being Moderated
    Mar 22, 2013 5:03 AM   in reply to kazzuni

    Because that's as far back as the date function goes. All dates are calculated from that point forward.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 22, 2013 6:42 AM   in reply to kazzuni

    Why would your date ever be "0000-00-00"?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 22, 2013 8:09 AM   in reply to kazzuni

    Why would the date ever be null? As long as the date has a non-zero, non-null value this function will work correctly.

     

    I'm a little confused by what you are doing here. So, you are pulling data from a table, and populating forms with it. This particular field is a date field, and the problem is that when the data for that field is a null, you are getting instead a date of 1970-01-01 displayed in that field - is that correct? What do you want to appear there when the data is null? Nothing?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 22, 2013 8:25 AM   in reply to kazzuni

    Try this -

     

    <input type="text" name="Data_chiusura" value="<?php $string=$row_Recordset1['data_chiusura']; echo empty($string)?'': date("d-m-Y", strtotime($string)); ?>" id="Data_chiusura">

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 22, 2013 8:56 AM   in reply to kazzuni

    Try this -

     

    <input type="text" name="Data_chiusura" value="<?php $string=$row_Recordset1['data_chiusura']; echo strtotime($string) <= strtotime('')?'': date("d-m-Y", strtotime($string)); ?>" id="Data_chiusura">

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 22, 2013 9:10 AM   in reply to kazzuni

    Good luck!

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points