views:

25

answers:

3

I want to store the current date & time which can be get by System.DateTime.Now in asp.net but while storing in Mysql it gives Error of Invalid Time.

A: 

What is the column type of your time column? I assume it's DateTime

You should not put the datetime in it through ASP.NET but directly in your query:

"INSERT INTO table (dateColumn, someVar) VALUES (NOW(), \"something\")"
Snake
A: 

why don't you use the MySQL now() function?

insert into mytable 
       ( id, MyDate  ) 
values ( 42, now()   )

If that is not possible, you will need to look into converting the client side date format into something the DB will understand.

lexu
+1  A: 

MySql stores DateTimes in the format 'YYYY-MM-DD HH:MM:SS'

So you need to do

System.DateTime.Now.ToString("YYYY-mm-dd HH:MM:SS");
Nick Allen - Tungle139