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
我没试过,你研究下吧,希望有帮助
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
我没试过,你研究下吧,希望有帮助
insert into 表(时间) values('"+textBox1.Text+"')
还可以设置时间字段的默认值为getdate(),自动获取当前时间
string a="2000-1-1"
insert into table (myTime) values ('"+ a + "')
insert into biao (date) values("+this.TextBox1.Text+")