Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 55
  1. #31
    Regular Coder
    Join Date
    Aug 2017
    Posts
    170
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I just tested again, Invalid datetime format: 1292 Incorrect date value: '12/31/2018'

  2. #32
    Regular Coder
    Join Date
    Jun 2010
    Location
    UK
    Posts
    203
    Thanks
    28
    Thanked 8 Times in 8 Posts
    Quote Originally Posted by richarddunnebsc View Post
    I just tested again, Invalid datetime format: 1292 Incorrect date value: '12/31/2018'
    Via your form input? or direct input as per my code I posted?

    even by adding:
    PHP Code:
    $_POST['ExpiryDate']  = filter_var($_POST['ExpiryDate'], FILTER_SANITIZE_STRING); 
    doesn't break the output, so what else are you doing to the date before it reaches the strtotime function?
    Last edited by PkraM; 01-12-2018 at 12:50 PM.
    Important I do not guarantee that any code sample that I post will work as intended and if you use it you do so entirely at your own risk.

    PHP - Because there is ALWAYS more than one way to do it!

  3. #33
    Regular Coder
    Join Date
    Jun 2010
    Location
    UK
    Posts
    203
    Thanks
    28
    Thanked 8 Times in 8 Posts
    I get:
    By using:
    PHP Code:
    <?php

    echo "Ref: https://www.codingforums.com/php/389519-datetime-displays-0000-00-00-00-00-00-a-2.html";

    $_POST['ExpiryDate'] = "12/31/2018";

    $expiryDate date('m d Y',strtotime($_POST['ExpiryDate']));  

    echo 
    "<h1>Expiry: " $expiryDate "</h1>\n";
    Important I do not guarantee that any code sample that I post will work as intended and if you use it you do so entirely at your own risk.

    PHP - Because there is ALWAYS more than one way to do it!

  4. #34
    Regular Coder
    Join Date
    Aug 2017
    Posts
    170
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I'm using this before processing data
    PHP Code:
    if ($_SERVER['REQUEST_METHOD'] === 'POST')
    {
        
    filter_var_array($_POSTFILTER_SANITIZE_STRING);
            
    //error checking

    All testing via form submission.

  5. #35
    Regular Coder
    Join Date
    Jun 2010
    Location
    UK
    Posts
    203
    Thanks
    28
    Thanked 8 Times in 8 Posts
    Quote Originally Posted by richarddunnebsc View Post
    I'm using this before processing data
    PHP Code:
    if ($_SERVER['REQUEST_METHOD'] === 'POST')
    {
        
    filter_var_array($_POSTFILTER_SANITIZE_STRING);
            
    //error checking

    All testing via form submission.
    Does it it work if you force the date in? like in my code I posted?
    Important I do not guarantee that any code sample that I post will work as intended and if you use it you do so entirely at your own risk.

    PHP - Because there is ALWAYS more than one way to do it!

  6. #36
    Regular Coder
    Join Date
    Aug 2017
    Posts
    170
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Tried
    PHP Code:
    $expiryDate date('m/d/Y',strtotime('12/31/2025')); 
    didn't work
    Invalid datetime format: 1292 Incorrect date value: '12/31/2025'

  7. #37
    Regular Coder
    Join Date
    Jun 2010
    Location
    UK
    Posts
    203
    Thanks
    28
    Thanked 8 Times in 8 Posts
    VERY quick and DIRTY but works!

    PHP Code:
    <?php

    filter_var_array
    ($_GETFILTER_SANITIZE_STRING);
    filter_var_array($_POSTFILTER_SANITIZE_STRING);

    echo 
    "<h1>Ref: https://www.codingforums.com/php/389519-datetime-displays-0000-00-00-00-00-00-a-2.html</h1>\n";

    if( ! isset(
    $_GET['action']) ) {
        
        
    dateForm();
        
    }
    else { 
    validateDate(); }

    function 
    dateForm() {

        echo 
    "<form method='POST' action='?action=GO'>

    <p>Expiry: <select name='expiry_month'>
    <option value='1' selected='selected'>January</option>
    <option value='2'>February</option>
    <option value='3'>March</option>
    <option value='4'>April</option>
    <option value='5'>May</option>
    <option value='6'>June</option>
    <option value='7'>July</option>
    <option value='8'>August</option>
    <option value='9'>September</option>
    <option value='10'>October</option>
    <option value='11'>November</option>
    <option value='12'>December</option>
    </select>
     &nbsp; <select name='expiry_day'>
    <option value='1'>1</option>
    <option value='2'>2</option>
    <option value='3'>3</option>
    <option value='4'>4</option>
    <option value='5'>5</option>
    <option value='6'>6</option>
    <option value='7'>7</option>
    <option value='8'>8</option>
    <option value='9'>9</option>
    <option value='10'>10</option>
    <option selected='selected'>11</option>
    <option value='12'>12</option>
    <option value='13'>13</option>
    <option value='14'>14</option>
    <option value='15'>15</option>
    <option value='16'>16</option>
    <option value='17'>17</option>
    <option value='18'>18</option>
    <option value='19'>19</option>
    <option value='20'>20</option>
    <option value='21'>21</option>
    <option value='22'>22</option>
    <option value='23'>23</option>
    <option value='24'>24</option>
    <option value='25'>25</option>
    <option value='26'>26</option>
    <option value='27'>27</option>
    <option value='28'>28</option>
    <option value='29'>29</option>
    <option value='30'>30</option>
    <option value='31'>31</option>
    </select>
     &nbsp; <select name='expiry_year'>
    <option selected='selected'>2018</option>
    <option value='2019'>2019</option>
    <option value='2020'>2020</option>
    <option value='2021'>2021</option>
    </select>

    <button type='submit'>Submit</button>

    </form>\n"
    ;

    }


    function 
    validateDate() {

    $_POST['ExpiryDate'] = "{$_POST['expiry_month']}/{$_POST['expiry_day']}/{$_POST['expiry_year']}";



    $expiryDate date('m d Y',strtotime($_POST['ExpiryDate']));  

    echo 
    "<h1>Expiry: " $expiryDate "</h1>\n";

    }
    Important I do not guarantee that any code sample that I post will work as intended and if you use it you do so entirely at your own risk.

    PHP - Because there is ALWAYS more than one way to do it!

  8. #38
    Regular Coder
    Join Date
    Jun 2010
    Location
    UK
    Posts
    203
    Thanks
    28
    Thanked 8 Times in 8 Posts
    I need to see how you are forming your expiry date...

    I think it is either your form HTML or the filter_var is breaking the $_POST because of the way you are using the filter_var...

    PHP Code:
    <?php

    error_reporting
    (E_ALL E_STRICT);

    $data = array(
        
    'product_id'    => 'libgd<script>',
        
    'component'     => '10',
        
    'versions'      => '2.0.33',
        
    'testscalar'    => array('2''23''10''12'),
        
    'testarray'     => '2',
    );

    $args = array(
        
    'product_id'   => FILTER_SANITIZE_ENCODED,
        
    'component'    => array('filter'    => FILTER_VALIDATE_INT,
                                
    'flags'     => FILTER_FORCE_ARRAY
                                
    'options'   => array('min_range' => 1'max_range' => 10)
                               ),
        
    'versions'     => FILTER_SANITIZE_ENCODED,
        
    'doesnotexist' => FILTER_VALIDATE_INT,
        
    'testscalar'   => array(
                                
    'filter' => FILTER_VALIDATE_INT,
                                
    'flags'  => FILTER_REQUIRE_SCALAR,
                               ),
        
    'testarray'    => array(
                                
    'filter' => FILTER_VALIDATE_INT,
                                
    'flags'  => FILTER_FORCE_ARRAY,
                               )

    );

    $myinputs filter_var_array($data$args);

    var_dump($myinputs);
    echo 
    "\n";
    ?>
    From PHP.net, there are different filters available depending on what data you are passing to the filter_var_array...
    Last edited by PkraM; 01-13-2018 at 10:41 AM.
    Important I do not guarantee that any code sample that I post will work as intended and if you use it you do so entirely at your own risk.

    PHP - Because there is ALWAYS more than one way to do it!

  9. #39
    Regular Coder
    Join Date
    Aug 2017
    Posts
    170
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I think the three selects is the better option over the text input. Currently redesigning the form.

  10. #40
    Regular Coder
    Join Date
    Jun 2010
    Location
    UK
    Posts
    203
    Thanks
    28
    Thanked 8 Times in 8 Posts
    Donít forget to check they have entered a valid day in the month - I have posted that code in this thread... ie stop them from entering 31st of February, etc...

  11. #41
    Regular Coder
    Join Date
    Jun 2010
    Location
    UK
    Posts
    203
    Thanks
    28
    Thanked 8 Times in 8 Posts
    Thinking about it there could be a inbuilt PHP to validate the date without my function... Iíll have to take a look again!

  12. #42
    Regular Coder
    Join Date
    Jun 2010
    Location
    UK
    Posts
    203
    Thanks
    28
    Thanked 8 Times in 8 Posts

  13. #43
    Regular Coder
    Join Date
    Aug 2017
    Posts
    170
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Something like this?
    PHP Code:
    if(!checkdate($_POST['ExpiryMonth'],$_POST['ExpiryDay'],$_POST['ExpiryYear'])
    {
         
    //display error message


  14. #44
    Regular Coder
    Join Date
    Jun 2010
    Location
    UK
    Posts
    203
    Thanks
    28
    Thanked 8 Times in 8 Posts
    Looks okay to me, but Iím using my phone now!

  15. #45
    Regular Coder
    Join Date
    Jun 2010
    Location
    UK
    Posts
    203
    Thanks
    28
    Thanked 8 Times in 8 Posts
    PHP Code:
    // NEW Date Validation, in preparation for mysql date...
        
    if( ! checkdate($IN['POST']['expiry_month'], $IN['POST']['expiry_day'], $IN['POST']['expiry_year']) ) {
            
            
    $errors .= " - <b>Sorry</b> but you have entered a invalid date!";
            
        }
        else {
        
            
    // MOVED into an else, so we dont get multiple error warnings about the inputted date...
            
    $expiryDate strtotime("{$IN['POST']['expiry_month']}/{$IN['POST']['expiry_day']}/{$IN['POST']['expiry_year']}");
        
            if ( ( 
    $expiryDate >= time() ) && ( ( $expiryDate <= time() + ( (60*60*24)*30 ) ) ) ) {
                
                
    $errors .= "<div>- Sorry but that expiry date is less than 30 days in advance!</div>\n";
                
            }
            elseif ( 
    $expiryDate time() ) {
                
                
    $errors .= "<div>- Expiry date is in the past.</div>\n";
                
            }
        
        } 
    That is how I have updated my date validation in my project...
    Important I do not guarantee that any code sample that I post will work as intended and if you use it you do so entirely at your own risk.

    PHP - Because there is ALWAYS more than one way to do it!


 
Page 3 of 4 FirstFirst 1234 LastLast

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
  •