Reputation:
I have 2 variables stored into mysql
:
Format: d/m/Y
Format: 24Hr
How could I concatenate them into one single variable like this:
2015-06-16T18:30
I tried with:
$new_datetime=$campaign_date.'T'.$campaign_time;
But it's not working
Upvotes: 1
Views: 657
Reputation: 4951
Try it,i tested it myself.
$db_date = date("Y-m-d",strtotime($db_date));
$db_time = date("h:i:s",strtotime($db_time));
echo $db_date.'T'.$db_time;
Upvotes: 1
Reputation: 59701
This should work for you:
(For the first date you have to change /
to -
so you can use date()
and you can change the order of d/m/Y
to Y-m-d
, after that it's a simple concatenation with the time at the end)
<?php
$campaign_date = "16/12/2014"; //Data from DB
$campaign_time = "18:00"; //Data from DB
echo $new_datetime = date("Y-m-d", strtotime(str_replace("/", "-", $campaign_date))) . "T" . date("H:i", strtotime($campaign_time));
?>
Output:
2014-12-16T18:00
Upvotes: 1