how to convert date and time to timestamp in php? -


i have date '07/23/2009' , time '18:11' , want timestamp out of : here example:

date_default_timezone_set('utc');  $d = str_replace('/', ', ', '07/23/2009'); $t = str_replace(':', ', ', '18:11'); $date = $t.', 0, '.$d; echo $date; echo '<br>'; echo $x = mktime("$date"); 

the issue $x gives me current timestamp.

any ideas?

it gives error because mktime function require values of numbers , function gives date . if try like

$h = 18; $i = 11; $s = 00; $m = 07; $d =23; $y = 2009; echo date("h-i-s-m-d-y",mktime($h,$i,$s,$m,$d,$y)); 

then work.

so complete code be

date_default_timezone_set('utc');  $d = str_replace('/', ',', '07/23/2009'); $t = str_replace(':', ',', '18:11'); $date = $t.',0,'.$d; $fulldate = explode(',',$date); echo '<br>'; $h = $fulldate[0]; $i = $fulldate[1]; $s = $fulldate[2]; $m = $fulldate[3]; $d =$fulldate[4]; $y = $fulldate[5];  echo date("h-i-s-m-d-y",mktime($h,$i,$s,$m,$d,$y)) . "<br>"; 

//if want timestamp use

echo strtotime("07/23/2009 18:11"); 

thanks


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -