Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2014
    Thanked 0 Times in 0 Posts

    problem with PHP 5.4 in getting reliable date conversion

    I have recently moved to a new managed server running PHP 5.4

    This is giving me inconsistent date conversion when applied to a Date field value in the mysql table.

    I had been using this formula before in PHP 5.3 and had no problems


    $values["DateField"] is pulled from the field "DateField" in the table where dates are in this format -- 2014-04-17 the field type is DATE

    the conversion that is supposed to happen is to: 17-04-2014

    But I am finding intermittent cases where the field reads a date value in July such as -- 2014-07-25

    But the php Email script where date("d-m-Y",strtotime($values["DateField"])) is used to convert that date to -- 25-07-2014

    comes back with the value 25-05-2014 ----- the DAY is correct, the Year is correct but the MONTH is May, the current month

    I see that the official PHP forum changelog shows bugs for date time functions that are being reported

    Has someone here had experience with PHP 5.4 specifically regarding doing such a string conversion correctly?

    I have tried such things as -- new DateTime($values["TimeField"]))->format('d/m/Y');

    But that fails because it totally injects TODAY's date no matter what $values["TimeField"] may be from the database table.

    Has a genius here a working formula?

    Thank you.

  • #2
    New Coder
    Join Date
    Dec 2011
    Thanked 14 Times in 14 Posts
    PHP Code:
    $values['dateField'] = '2014-04-17';

    $myDate = new DateTime($values['dateField']);

    $output $myDate->format('d-m-Y');

    Since this isn't the standard date format (0000-00-00 00:00:00) in MySQL, you'll have to change that also to reflect the correct format. Otherwise you'll be getting unexpected results.
    Last edited by Strider64; 05-20-2014 at 12:42 PM.
    True courage is about knowing not when to take a life, but when to spare one. PDO Tutorial

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Your Monitor
    Thanked 527 Times in 514 Posts
    Blog Entries
    Yes I've had glitches with dates in php between versions, can't remember exactly what but I had to rewrite a fair few bits of code. I've never liked the mysql datetime thing to be honest and always store my times/dates as interger timestamps instead.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #4
    New to the CF scene
    Join Date
    May 2014
    Thanked 0 Times in 0 Posts
    Thanks for your quick responses, guys! Much appreciated.


    Posting Permissions

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