用getdate()取的值如何只显示日期而不显示时间
1、怎样在ASP取出的SQL Server里数据类型为datetime默认值为getdate()的字段,而且只显示日期而不显示时间?
除去用year(getdate()), month(getdate()), day(getdate())的方法依次取出年月日还有其他方法么?
例如该字段名为infotime.
2、如果在SQL Server想直接存储日期(不含时间),该如何设置字段的默认值?
问题点数:20、回复次数:7Top
1 楼xiaobird1(Vincent)回复于 2005-08-03 15:43:41 得分 6
默认值CONVERT(VARCHAR(10), GETDATE(), 120)Top
2 楼rainxiang(楚王好细腰 后宫多饿死)回复于 2005-08-03 15:47:57 得分 2
select convert(varchar(10),getdate(),120)Top
3 楼xiaobird1(Vincent)回复于 2005-08-03 15:49:03 得分 0
1、查看FormatDateTime函数Top
4 楼xiaobird1(Vincent)回复于 2005-08-03 15:50:37 得分 4
FormatDateTime Function
Returns an expression formatted as a date or time.
FormatDateTime(Date[, NamedFormat])
Arguments
Date
Required. Date expression to be formatted.
NamedFormat
Optional. Numeric value that indicates the date/time format used. If omitted, vbGeneralDate is used.
Settings
The NamedFormat argument has the following settings:
Constant Value Description
vbGeneralDate 0 Display a date and/or time. If there is a date part, display it as a short date. If there is a time part, display it as a long time. If present, both parts are displayed.
vbLongDate 1 Display a date using the long date format specified in your computer's regional settings.
vbShortDate 2 Display a date using the short date format specified in your computer's regional settings.
vbLongTime 3 Display a time using the time format specified in your computer's regional settings.
vbShortTime 4 Display a time using the 24-hour format (hh:mm).
Remarks
The following example uses the FormatDateTime function to format the expression as a long date and assign it to MyDateTime:
Function GetCurrentDate
' FormatDateTime formats Date in long date.
GetCurrentDate = FormatDateTime(Date, 1)
End Function
Top
5 楼ghaihua(晨昕)回复于 2005-08-03 15:52:05 得分 0
用convert(varchar(10),getdate(),111)试试Top
6 楼yangsky971(潇洒走一回)回复于 2005-08-03 15:57:04 得分 2
Format(ThisTime, xxx)
xxx格式如下:
格式符
含义
日
d
显示不带0的日期(1-31)
dd
显示带0的日期(01-31)
ddd
以Sun-Sat格式显示日期
dddd
以Sunday-Saturday格式显示日期
ddddd
以年月日标准格式显示日期
月/分钟
m
显示不带0的月,如果后面紧跟h或hh则显示不带0的分
mm
显示带0的月,如果后面紧跟h或hh则显示带0的分
mmm
以Jan-Dec显示月份
mmmm
以January-December显示月份
年
yy
以两位数显示年(00-99)
yyy
以四位数显示年(1900-2040)
Top
7 楼hrbwzp2(蓝天白云飘)回复于 2005-08-03 16:29:21 得分 6
DateValue(getdate())Top




