asp.net(c#) sql 字段datetime类型,怎么用insert into语句只插入时间从文本框获取的时间

就是去掉自动增加的1900-1-1
2024年11月30日 09:49
有5个网友回答
网友(1):

SQL命令中DateTime格式大全

Code in C# :
DateTime MyDate = DateTime.Now;
sSQL = "Insert Into Article (Title,CreatedDate) Values (\'New Title\',\'" + MyDate.Format( "g", null ) + "\')";
格式字符参考表:

Format character
Description
Default return format

d
Short date pattern
MM/dd/yyyy

D
Long date pattern
dddd, MMMM dd, yyyy

f
Full (long date + short time)
dddd, MMMM dd, yyyy HH:mm

F
Full date time pattern (long date + long time)
dddd, MMMM dd, yyyy HH:mm:ss

g
General (short date + short time)
MM/dd/yyyy HH:mm

G
General (short date + long time)
MM/dd/yyyy HH:mm:ss

m,M
Month day pattern
MMMM dd

r,R
RFC1123 pattern
ddd, dd MMM yyyy HH\':\'mm\':\'ss\'GMT\'

s
Sortable date time pattern: conforms to ISO 8601
yyyy-MM-dd HH:mm:ss

t
Short time pattern
HH:mm

T
Long time pattern
HH:mm:ss

u
Similar to "s"but uses universal time instead of local time.
yyyy-MM-dd HH:mm:ss

U
Universal sortable date time pattern
dddd, MMMM dd, yyyy HH:mm:ss

Y,y
Year month pattern
MMMM, yyyy

我没试过,你研究下吧,希望有帮助

网友(2):

SQL命令中DateTime格式大全

Code in C# :
DateTime MyDate = DateTime.Now;
sSQL = "Insert Into Article (Title,CreatedDate) Values (\'New Title\',\'" + MyDate.Format( "g", null ) + "\')";
格式字符参考表:

Format character
Description
Default return format

d
Short date pattern
MM/dd/yyyy

D
Long date pattern
dddd, MMMM dd, yyyy

f
Full (long date + short time)
dddd, MMMM dd, yyyy HH:mm

F
Full date time pattern (long date + long time)
dddd, MMMM dd, yyyy HH:mm:ss

g
General (short date + short time)
MM/dd/yyyy HH:mm

G
General (short date + long time)
MM/dd/yyyy HH:mm:ss

m,M
Month day pattern
MMMM dd

r,R
RFC1123 pattern
ddd, dd MMM yyyy HH\':\'mm\':\'ss\'GMT\'

s
Sortable date time pattern: conforms to ISO 8601
yyyy-MM-dd HH:mm:ss

t
Short time pattern
HH:mm

T
Long time pattern
HH:mm:ss

u
Similar to "s"but uses universal time instead of local time.
yyyy-MM-dd HH:mm:ss

U
Universal sortable date time pattern
dddd, MMMM dd, yyyy HH:mm:ss

Y,y
Year month pattern
MMMM, yyyy

我没试过,你研究下吧,希望有帮助

网友(3):

insert into 表(时间) values('"+textBox1.Text+"')

还可以设置时间字段的默认值为getdate(),自动获取当前时间

网友(4):

string a="2000-1-1"

insert into table (myTime) values ('"+ a + "')

网友(5):

insert into biao (date) values("+this.TextBox1.Text+")