• Resolved marlene4us

    (@marlene4us)


    I am trying to use the iso8601_to_datetime to convert 2014-09-05T01:34:10.567Z into a WP readable format. No effect.

    $dateCreated = '2014-09-05T01:34:10.567Z';
    $iso = iso8601_to_datetime($dateCreated);
    $date = get_date_from_gmt($iso);
    echo $iso;
    echo $date;

    result($iso): 2014-09-05T01:34:10.567Z
    result($date): 1970-01-01 00:00:00

    *UTC-3

    Am I using this function incorrectly?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Take out the dashes in the date.

    $dateCreated = '20140905T01:34:10.567Z';
    $iso = iso8601_to_datetime($dateCreated);
    $date = get_date_from_gmt($iso);
    echo $iso;
    echo $date;
    Thread Starter marlene4us

    (@marlene4us)

    I tested it and it worked … thank you!
    Why? How does it work?
    Is there any function for this??

    Thread Starter marlene4us

    (@marlene4us)

    I do not understand why removing the dashes in the date. Why the original form of date does not work? ( Could you indicate the documentation for me to study? ).

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    That is a very old function and there likely isn’t any documentation. Just read the function’s code in the source. It isn’t expecting dashes there.

    If you need to convert arbitrary formats, then use the built in PHP code, like strtotime() or some such.

    Thread Starter marlene4us

    (@marlene4us)

    Thank you for your clear and helpful explanation.

    I created a function:

    function iso8601_without_dashes($iso) {
    	$year = substr($iso, 0, 4);
    	$month = substr($iso, 5, 2);
    	$day = substr($iso, 8, 2);
    	$hour = substr($iso, 11, 2);
    	$minute = substr($iso, 14, 2);
    	$second = substr($iso, 17, 2);
    	$timezone = substr($iso, 19);
    	return  $year.$month.$day.'T'.$hour.':'.$minute.':'.$second.$timezone;
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘I am having issues with iso8601_to_datetime Function, help me’ is closed to new replies.