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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2014
    Posts
    3
    Thanks
    0
    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

    date("d-m-Y",strtotime($values["DateField"]))

    $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. #2
    Regular Coder Strider64's Avatar
    Join Date
    Dec 2011
    Posts
    206
    Thanks
    5
    Thanked 30 Times in 30 Posts
    PHP Code:
    $values['dateField'] = '2014-04-17';

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

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

    echo 
    $output
    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.
    "A person who never made a mistake never tried anything new." ~ Albert Einstein https://www.triviaintoxication.com/

  3. #3
    Master Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    5,042
    Thanks
    106
    Thanked 591 Times in 578 Posts
    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.
    Quote Originally Posted by deathshadow View Post
    So seriously, loosen up that tie, let out the belt, and try relating to normal people on the street instead of the gentleman's club crowd.

  4. #4
    New to the CF scene
    Join Date
    May 2014
    Posts
    3
    Thanks
    0
    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
  •