get datetime filed to mysql db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

get datetime filed to mysql db

Post by yaron »

Hi all,
I need to store the directory date (modify date) to mysql db.
I have a datetime field and here is the code I wrote:

$dDate=date("Y m d H i s", filemtime("$path"));
$insSql="INSERTINTO table (path,mdate) VALUES ('$path','$dDate')";
mysql_query($insSql);

the path is stored correctly but the date reamins empty and appear in the db.
0000-00-00 00:00:00
How can I correct it?
Thanks
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

no need....
Got it :-)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

It could help others later if you post the solution you found...

Mac
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

i think his issue was that the datetime field expects yyyy-mm-dd hh:mm:ss and if you don't have it like tht it's not correct so it goes to the default since your supplied value is invalid
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

That's what I thought, but I like to see people posting their solutions.

Mac
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

sorry guys
solution:
$dDate=date("Y-m-d H:i:s", filemtime("$path"));
simple as that...
:)
Post Reply