Gustavo Andriuolo Gustavo Andriuolo -4 years ago 170
PHP Question

PHP Format date yyyy-mm-ddThh:ii:ss to Y-m-d h:i:s

i need to convert a date with this format (2017-06-14T08:22:29.296-03:00) to Y-m-d H:i:s. I take that date from an xml response from a soap service, And i need to check if the expiration date is less than the actual date.

I have this and works OK on localhost, but when is uploaded to other server, i have validation problems:

if($wsaa->get_expiration() < date("Y-m-d h:m:i")) {
if ($wsaa->generar_TA()) {
echo '<br>Nuevo Ticket de Acceso Generado';
} else {
echo '<br>No se pudo obtener ticket de acceso';
} else {
echo '<br>TA expira:' . $wsaa->get_expiration();

$wsaa->get_expiration() return 2017-06-14T08:22:29.296-03:00

I tried to format the date but return with a few minutes of diff.

Answer Source

You can use date function for format and use strtotime to convert current date to timestamp that date function needed:

$datetime = '2017-06-14T08:22:29.296-03:00';

$format_date  = date('Y-m-d H:i:s', strtotime($datetime));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download