user4096916
user4096916

Reputation:

STRTOTIME take date and data from mysql and concatenate them on php

I have 2 variables stored into mysql:

  1. campaign_date Format: d/m/Y
  2. campaign_time 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

Answers (2)

Raham
Raham

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

Rizier123
Rizier123

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

Related Questions