prasad1250
prasad1250

Reputation: 162

Unable to store date and timestamp values in mysql

I have date and timestamp fields in mysql table.

$timeString="Thu Jul 26 22:45:09 +0000 2012";

$time=strtotime($timeString);

$date=date('Y-m-d', $timeString);

When I execute the query it storing the following values:

date 0000-00-00 time 0000-00-00 00:00:00

Can anyone fix my problem.

Upvotes: 0

Views: 306

Answers (2)

Johndave Decano
Johndave Decano

Reputation: 2113

$date = new DateTime('Thu Jul 26 22:45:09 +0000 2012');
echo $date->format('Y-m-d H:i:s');

Upvotes: 0

gherkins
gherkins

Reputation: 14985

you're trying to build your date from $timestring (the string) instead of $time(the timestamp )

try:

$timeString="Thu Jul 26 22:45:09 +0000 2012";

$time=strtotime($timeString);

$date=date('Y-m-d', $time);

you should enable php warnings in your development environment. date would have told you :)

date() expects parameter 2 to be long, string given

Upvotes: 6

Related Questions