如何取本月第一天和当前的年月日,

skyearth 2009-08-11 11:50:19
如题,在asp里用!如第一天2009-8-1 当前2009-8-11
...全文
134 点赞 收藏 8
写回复
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
asasas20020 2009-08-11
项目里用的日期格式转换函数。解决你的问题小菜一碟
<%



'2009-08-01

'2009-08-11

response.write(fDateFormatChange(Year(Now)&Right("00"&Month(Now),2)&"01","-")&"<BR>")



response.write(fDateFormatChange(Year(Now)&Right("00"&Month(Now),2)&Right("00"&Day(Now),2),"-"))





Function fDateFormatChange(ByVal strYMD, ByVal strDelimiter)

Dim strEditYear

Dim strEditMonth

Dim strEditDay

Dim strFileDir

Dim objItems





Select Case Len(Trim(strYMD))

Case 4 'MMDD

strEditYear = ""

strEditMonth = Mid(strYMD, 1, 2)

strEditDay = Mid(strYMD, 3, 2)

Case 5 'MM/DD

strEditYear = ""

strEditMonth = Mid(strYMD, 1, 2)

strEditDay = Mid(strYMD, 4, 2)

Case 6 'YYYYMM

strEditYear = Mid(strYMD, 1, 4)

strEditMonth = Mid(strYMD, 5, 2)

strEditDay = ""

Case 7 'YYYY/MM

If IsNumeric(Mid(strYMD, 1, 1)) Then

strEditYear = Mid(strYMD, 1, 4)

strEditMonth = Mid(strYMD, 6, 2)

strEditDay = ""

Else

strEditYear = Mid(strYMD, 1, 3)

strEditMonth = Mid(strYMD, 4, 2)

strEditDay = Mid(strYMD, 6, 2)

End If

Case 8 'YYYYMMDD

strEditYear = Mid(strYMD, 1, 4)

strEditMonth = Mid(strYMD, 5, 2)

strEditDay = Mid(strYMD, 7, 2)

Case 9 '(GYY/MM/DD)

strEditYear = Mid(strYMD, 1, 3)

strEditMonth = Mid(strYMD, 5, 2)

strEditDay = Mid(strYMD, 8, 2)

Case 10 'YYYY/MM/DD

strEditYear = Mid(strYMD, 1, 4)

strEditMonth = Mid(strYMD, 6, 2)

strEditDay = Mid(strYMD, 9, 2)

Case Else

strEditYear = ""

strEditMonth = ""

strEditDay = ""

End Select



If strEditYear <> "" Then

strEditYear = strEditYear & strDelimiter

End If



If strEditDay <> "" Then

strEditDay = strDelimiter & strEditDay

End If



fDateFormatChange = strEditYear & strEditMonth & strEditDay



End Function

%>
回复
老彭1980 2009-08-11
补充:本月第一天用于运算之前,可以先用如下代码格式化成日期格式。

cdate(year(date())&"-"&month(date())&"-1")
回复
老彭1980 2009-08-11

'本月第一天
year(date())&"-"&month(date())&"-1"
'当天
date()
回复
hookee 2009-08-11


today = Date()
d = Day(today)-1
first = DateAdd("d", -d, today)


Response.Write Year(today) & "-" & Month(today) & "-" & Day(today)

Response.Write Year(first) & "-" & Month(first) & "-" & Day(first)
回复
skyearth 2009-08-11
我说的挺明白呀,论坛有这么问的,不过我觉得回答的不太对,所以又开个贴
回复
skyearth 2009-08-11
?????????俄,当前直接用达特(),第一天不会呀,我水平太低,
回复
shenzhenNBA 2009-08-11


<%=now()%>
回复
shenzhenNBA 2009-08-11
?问得好怪哦....
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告