iamlancer
iamlancer

Reputation: 117

Convert to mysql TIMESTAMP

How can i convert this values to insert into mysql TIMESTAMP.

$time=12 am;

$time=date("H:i:s", strtotime($mtime));

the above thing doesn't work

is there any better solution to do this.

Upvotes: 0

Views: 208

Answers (3)

aloneibreak
aloneibreak

Reputation: 335

$time=12 am;
$time=date("H:i:s", strtotime($mtime));

$time = 12 am, but you're trying strtotime($mtime). maybe your problem in wrong variable?

Upvotes: 0

Clive
Clive

Reputation: 36956

I think the problem is you're seeing '00:00:00' and assuming that's wrong...it's not. '00:00:00' is how midnight is represented. If you want to get today at midnight this will do it:

$now = time();
$time = mktime(0, 0, 0, date('m', $now), date('d', $now), date('Y', $now));
$time = date("Y-m-d H:i:s", $time);

This will return a string like this: 2011-10-04 00:00:00 which I think is what you're after.

Upvotes: 1

Lee Price
Lee Price

Reputation: 5212

 $time = "12am";
 $time=date("H:i:s", strtotime($time));

That should work

Upvotes: 0

Related Questions