开发者

store Current Date & time in MySql Using ASP.net

I want to store the current date & time which can be ge开发者_Go百科t by System.DateTime.Now in asp.net but while storing in Mysql it gives Error of Invalid Time.


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");


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\")"


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜