Reputation: 162
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
Reputation: 2113
$date = new DateTime('Thu Jul 26 22:45:09 +0000 2012');
echo $date->format('Y-m-d H:i:s');
Upvotes: 0
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