tags:

views:

35

answers:

3

I have two sets of information.

One is a date that is in Tuesday, January 26, 2010 format. This is $date

Now i also have one of two things for time. $stime can be either 7:30pm or Tuesday, January 26, 2010 7:30pm

What i need to do, is first, convert $stime to HH:MM:SS format, then combine it with $date and convert the two together to YYY-MM-DD HH:MM:SS format.

+1  A: 

You could use the strtotime function to convert if for you, then you can use the date function to output it in the required format. see the respective doc pages for the two functions.

Toby Allen
+3  A: 
  date('Y-m-d H:i:s', strtotime('Tuesday, January 26, 2010 7:30pm'));

Or for the two separately:

 date('Y-m-d H:i:s', strtotime('$date $time'));

EDIT: Actually, this should work, converting time first, then concatenating in the second line.:

   $time = date('H:i:s', strtotime('$time'));
   date('Y-m-d H:i:s', strtotime('$date $time'));
Gazler
+2  A: 
$d = date('Y-m-d', strtotime($date));
$t = date('H:i:s', strtotime($stime));

$final = date('Y-m-d H:i:s', $d . ' ' . $t);

very hacky.. but should work..

Yash
sorry Gazler.. dint see yr answer before posting..
Yash
Was probably posted during my edit when the more correct solution dawned on me. ;)
Gazler
some dates are throwing crazy stuff like 1969-12-31 18:33:30
Patrick
can you give me an example date?
Yash