注册 登录
编程论坛 ASP技术论坛

如何让时间只显示月日时呢?

dushui265 发布于 2007-10-02 10:54, 2008 次点击

我数据库中的日期格式是完整的,现在只想在页面中显示月日时,如何实现呢??

4 回复
#2
litianyi5202007-10-02 17:22

year(rs(“time”))
month(rs(“time”))
date(rs(“time”))
#3
tianyu1232007-10-02 21:32
以下是引用litianyi520在2007-10-2 17:22:24的发言:

year(rs(“time”))
month(rs(“time”))
date(rs(“time”))

应该为:

day(rs("time"))

#4
dushui2652007-10-03 10:21
谢谢楼上各位了!!!!
#5
天涯听雨2007-10-04 11:29
'该函数作用:按指定参数格式化显示时间。
'numformat=1:将时间转化为yyyy-mm-dd hh:nn格式。
'numformat=2:将时间转化为yyyy-mm-dd格式。
'numformat=3:将时间转化为hh:nn格式。
'numformat=4:将时间转化为yyyy年mm月dd日 hh时nn分格式。
'numformat=5:将时间转化为yyyy年mm月dd日格式。
'numformat=6:将时间转化为hh时nn分格式。
'numformat=7:将时间转化为yyyy年mm月dd日 星期×格式。
'numformat=8:将时间转化为yymmdd格式。
'numformat=9:将时间转化为mmdd格式。
Function FormatDate(shijian,numformat)
dim ystr,mstr,dstr,hstr,nstr '变量含义分别为年字符串,月字符串,日字符串,时字符串,分字符串

if isnull(shijian) then
numformat=0
else
ystr=DatePart("yyyy",shijian)

if DatePart("m",shijian)>9 then
mstr=DatePart("m",shijian)
else
mstr="0"&DatePart("m",shijian)
end if

if DatePart("d",shijian)>9 then
dstr=DatePart("d",shijian)
else
dstr="0"&DatePart("d",shijian)
end if

if DatePart("h",shijian)>9 then
hstr=DatePart("h",shijian)
else
hstr="0"&DatePart("h",shijian)
end if

if DatePart("n",shijian)>9 then
nstr=DatePart("n",shijian)
else
nstr="0"&DatePart("n",shijian)
end if

if DatePart("s",shijian)>9 then
sstr=DatePart("s",shijian)
else
sstr="0"&DatePart("s",shijian)
end if
end if

select case numformat
case 0
FormatDate=ystr&"-"&mstr&"-"&dstr&" "&hstr&":"&nstr&":"&sstr
case 1
FormatDate=ystr&"-"&mstr&"-"&dstr&" "&hstr&":"&nstr
case 2
FormatDate=ystr&"-"&mstr&"-"&dstr
case 3
FormatDate=hstr&":"&nstr
case 4
FormatDate=ystr&"年"&mstr&"月"&dstr&"日 "&hstr&"时"&nstr&"分"
case 5
FormatDate=ystr&"年"&mstr&"月"&dstr&"日"
case 6
FormatDate=mstr&"月"&dstr&"日 "&hstr&"时"&nstr&"分"
case 7
FormatDate=ystr&"年"&mstr&"月"&dstr&"日 "&WeekdayName(Weekday(shijian))
case 8
FormatDate=right(ystr,2)&mstr&dstr
case 9
FormatDate=mstr&dstr
end select
End Function
1