我有一个日历程序,它驻留在服务器上,这个程序以这样的格式将日期存储到数据库中:
YYYYMMDD
在asp中是否有“容易”的方法来管理这些日期?例如,让我们假设2013年4月20日为日期:
20130420我们希望将这一日期再延长20天,因此我们想要制作:
20130510知道吗?在asp中有integerTOdate转换吗?或者我可以用什么东西把“天”加到20130420这个数字上?
发布于 2013-04-15 14:40:04
像这样的东西(未经测试):
Dim strDate, theDate, theDatePlusTwentyDays
Dim Year, Month, Day
' The date is stored as a string...
strDate = "20130420"
' Extract the components of the date
Year = Mid(strDate, 1, 4)
Month = Mid(strDate, 5, 2)
Day = Mid(strDate, 7, 2)
' Convert the components of the date into a datetime object
theDate = DateSerial(Year, Month, Day)
' Add 20 days using DateAdd
theDatePlusTwentyDays = DateAdd("d", 20, theDate)发布于 2013-04-15 14:29:41
是的,您可以使用DateAdd函数
Response.Write(DateAdd("d",1,Now()))你需要先把你的约会安排成这样
<%
dim _dateOnServer
dim _formattedDate
dim _day
dim _month
dim _year
_dateOnServer = 20130420
_year = Left(_dateOnServer,4)
_month = Mid(_dateOnServer,5,2)
_day = Right(_dateOnServer,2)
_formattedDate = _month &"-"& _day &"-"& _year
dim _newDate
_newDate = DateAdd("d",20, _formattedDate )
_day = Left(_newDate,2)
_month = Mid(_newDate,4,2)
_year = Right(_newDate,4)
dim _newDateFormat
_newDateFormat = _year & _month & _day
%>发布于 2013-04-29 08:40:06
一种能够完全控制订单和格式的解决方案.
strDay = Day(Date)
strMonth = Month(Date)
strYear = Year(Date)
strHours = Hour(Now)
strMins = Minute(Now)
strSecs = Second(Now())
if len(strMonth) = 1 then
strMonth = "0" & strMonth
end if
if len(strDay) = 1 then
strDay = "0" & strDay
end if
if len(strHours) = 1 then
strHours = "0" & strHours
end if
if len(strMins) = 1 then
strMins = "0" & strMins
end if
if len(strSecs) = 1 then
strSecs = "0" & strSecs
end if
strDateAdded = strYear & "-" & strMonth & "-" & strDay
strDateAddedTime = strDateAdded & " " & strHours & ":" & strMins使用这种方法,您可以完全控制订单,即使在不同的时区运行web应用程序,您仍然保持DD/MM格式.或任何您想要的顺序,如MM-DD-YY (通过重新排序和修剪一年)。就我个人而言,我更喜欢YYYY-MM-DD,因为使用ASC和DESC排序要容易得多,即:易于阅读,因为所有行都有相同数目的字符,如:
2013-04-01 03:15
2013-04-09 10:15
2013-04-22 07:15
2013-04-23 10:15
2013-04-23 10:60
2013-10-25 12:01
2013-10-25 12:59而不是:
2013-4-1 3:15
2013-4-9 10:15
2013-4-22 7:15
2013-4-23 10:15
2013-4-23 10:60
2013-10-25 12:1
2013-1-25 12:59https://stackoverflow.com/questions/16017717
复制相似问题