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.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    date field problem in PHP form

    Every so often an entry will set it self to a default date of 01 January 01:00
    is there anything I can place in this string to ensure this does not happen or any ideas why this may be happening every so often not sure what other parts to paste but the date entry field is as follows

    Code:
    <td><input type='hidden' name='lead_date' value='<?php echo date('Y-m-d');?>'><?php echo date('d/m/Y');?></td>
    cheers

    mike.

  • #2
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    and this is were field displays

    Code:
        <h5><?php 
                                        echo date('l jS F, H:i',strtotime($row['date_and_time_entered']));
                                    ?></h5>

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    How is it you wanted the output to look? Format of 'l jS F, H:s' would indicate you want output to show as 'Thursday 18th April 07:00' for example. That seems to match your original post.
    If the time is showing as january and its not supposed to, that indicates that your data is no good and it cannot interpret the date properly and instead defaults to unix epoch (December 31, 1969 - January 1, 1970 depending on timezone). Assuming the dbms datatype is DateTime, than the record is parsable using strtotime. You can still get bad data by either giving the dbms an entry it doesn't understand (assuming you used Y-m-d that's fine) defaulting the entry to null on failure, or there is no entry to start with.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    that's the format it displays and we want to keep. and every so often its defaulting to January 1, 1970 as u say. The problem is im not sure how to fix this I have inherited this code and been asked to resolve. ideas?

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    It'll be your data. $row['date_and_time_entered'] has hit a condition in which it isn't parsable by the strtotime, so it instead returns false (or -1 depending on PHP version). In either case, worst case scenario you are behind by one second and that would become December 31, 1969 11:59:59 instead.
    As for fixing it, it depends on what you want to do. You can easily determine if the DateTime is valid by blocking it in an if:
    PHP Code:
    $iTime strtotime($row['date_and_time_entered']);
    if (
    version_compare(PHP_VERSION'5.1.0''<') && $iTime == -|| $iTime === false)
    {
        
    // this is an error condition.
    }
    else
    {
       
    // this is aok

    Or by using the DateTime object.
    Doesn't really "fix" the problem, but at least it lets you decide what you want to do with it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    im looking at the input that they use and the date and time is already filled in to the time the page loads. and they cannot change this so its not actually an input field. just need to try and determine why this is happening and why its not all the time just every so often

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Check the error logs. Perhaps there is no property to dereference when you fetch from the database. I've made the assumption that the db is under a DateTime datatype, but it may not be.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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