GIC GIC - 1 month ago 14
PHP Question

Format the infusionsoft return date using php

i worked on the code to get subscription start date & end date from the infusionsoft and it return in this format

Start date=20151217T00:00:00

EndDate=20161217T00:00:00

how i can format to YYYY/MM/DD H:M:S ?

and what the 'T' stands for

Answer

The T, according to the the ISO 8601 standard, is the delimiter between the date and time parts.

See: ISO 8601 standard, Wikipedia

There are two functions you could use:

  1. strtotime(date_time_string)

    Converts a date/time string into a timestamp.

  2. date(format, timestamp)

    Formats a timestamp into a string according to "format".

The example code…

$so_string = '20151217T00:00:00';
$eo_string = '20161217T00:00:00';

$sd_stamp = strtotime($so_string);
$ed_stamp = strtotime($eo_string);

$f_datetime ='Y/m/d H:i:s';

echo 'Start date<br />';
echo '&nbsp;&nbsp;&nbsp;original: '  . $so_string . '<br />';
echo '&nbsp;&nbsp;&nbsp;timestamp: ' . $sd_stamp . '<br />';
echo '&nbsp;&nbsp;&nbsp;formatted: ' . date($f_datetime,$sd_stamp) . '<br /><br />';
echo 'End date<br />';
echo '&nbsp;&nbsp;&nbsp;original: '  . $eo_string . '<br />';
echo '&nbsp;&nbsp;&nbsp;timestamp: ' . $ed_stamp. '<br />';
echo '&nbsp;&nbsp;&nbsp;formatted: ' . date($f_datetime,$ed_stamp) . '<br />';

…will produce this output:

Start date
   original: 20151217T00:00:00
   timestamp: 1450306800
   formatted: 2015/12/17 00:00:00

End date
   original: 20161217T00:00:00
   timestamp: 1481929200
   formatted: 2016/12/17 00:00:00