2
How do I concatenate these two variables to ISO format (Y-m-d H:i:s)?
$data = '17-04-2018';
$hora = '16:12';
2
How do I concatenate these two variables to ISO format (Y-m-d H:i:s)?
$data = '17-04-2018';
$hora = '16:12';
6
You can use these two functions:
date_create http://php.net/manual/en/function.date-create.php
date_format http://php.net/manual/en/function.date-format.php
$data = '17-04-2018';
$hora = '16:12';
$date = date_create($data . $hora);
$result = date_format($date, 'Y-m-d H:i:s');
att,
5
Here’s what you can do:
1 - We use strtotime() to convert into Unix timestamp;
2 - We use date() to convert this timestamp to the desired format:
<?php
$data = '17-04-2018';
$hora = '16:12';
$timestamp = strtotime($data. ' ' .$hora);
echo date('Y-m-d H:i:s', $timestamp); // 2018-04-17 16:12:00
It worked great. Thanks for the demonstration.
-4
I have a great job here in case anyone needs it.
function formatadata($data){
setlocale(LC_TIME, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
date_default_timezone_set('America/Sao_Paulo');
return strftime('%A, %d de %B de %Y %H:%M:%S' , strtotime($data));}
This code does not answer the question the user wants to know how to concatenate two strings to form a timestamp.
Browser other questions tagged php datetime
You are not signed in. Login or sign up in order to post.
Both this and the other answer worked perfectly. Thank you
– White