SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2003
    0 Post(s)
    0 Thread(s)

    problem with date... inserted as 1969-12-31

    I am having problems with getting the dates entered into a form correctly inserted into the database. As it stands, the dates are being inserted as 1969-12-31.

    I am working with a script that appears to be abandoned by its author, so although I know very little about MySQL, I am trying my best to learn enough to get this working. I have scoured the internet before posting here, but I am still no closer to finding a solution.

    There is a form with name, description, start date and end date fields. I wasn't sure what format to enter the date in the start and end date fields, but I have tried every format I could think of and still get the incorrect date being inserted.

    I am not sure if the problems is with strtotime() -- I have read about it but don't understand fully to know if it there is anything incorrect in my code.

    Here is the code for the form--
    <form name="challengeform" id="challengeform" class="wrap" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
            <input type="hidden" name="action" value="<?php echo $mode?>">
            <input type="hidden" name="challengeID" value="<?php echo $challengeID?>">
            <div id="item_manager">
                <div style="float: left; width: 98%; clear: both;" class="top">
                    <!-- List URL -->
                    <fieldset class="small">
                            <tr><td>name</td><td><input type="text" name="challenge_name" class="input" value="<?php if ( !empty($data) ) echo htmlspecialchars($data->name); ?>"></td></tr>
                            <tr><td>description</td><td><input type="text" name="challenge_description" class="input" value="<?php if ( !empty($data) ) echo htmlspecialchars($data->description); ?>"></td></tr>
                            <tr><td>date start</td><td><input type="text" name="challenge_start" class="input" value="<?php if ( !empty($data) ) echo htmlspecialchars(date("d/m/Y",strtotime($data->dateStart))); ?>"></td></tr>
                            <tr><td>date end</td><td><input type="text" name="challenge_end" class="input" value="<?php if ( !empty($data) ) echo htmlspecialchars(date("d/m/Y",strtotime($data->dateEnd))); ?>"></td></tr>
                    <br />
                    <input type="submit" name="save" class="button bold" value="Save &raquo;" />
                <div style="clear:both; height:1px;">&nbsp;</div>
    function strtotime_au($str)
       $str = preg_replace("/^\s*([0-9]{1,2})[\/\. -]+([0-9]{1,2})[\/\. -]*([0-9]{0,4})/", "\\2/\\1/\\3", $str);
       $str = trim($str,'/');
       return strtotime($str);
    And to insert into db--
        $sql = "insert into " . WP_CHALLENGE_TABLE . " set " 
                        . "name='" . mysql_escape_string($challenge_name) . "', "
                        . "description='" . mysql_escape_string($challenge_description) . "', "
                        . "dateStart='" . date("Y-m-d",$challenge_start) . "', "
                        . "dateEnd='" . date("Y-m-d",$challenge_end) . "'";
    Hopefully I have provided enough of the script or the right part of it... I appreciate anyone who can offer help with this!

  2. #2
    SitePoint Member
    Join Date
    Feb 2009
    0 Post(s)
    0 Thread(s)
    In Unix/Linux time is measured in seconds from Jan 1, 1970. In other words time the number 0 when interpreted as a time will be Jan 1/70. In your case, because of your time zone setting, its giving Dec 31/69.

    I don't know enough php to debug your problem but if you find the zero then you have found your problem.

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    France, deep rural.
    17 Post(s)
    1 Thread(s)
    Start with your html form, and try and enter exactly what the database expects to see.


    Honestly, there could be lots of other stuff going on behind this, so you'd better get someone to sort it out for you.

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts