首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何处理数字6位数日期

如何处理数字6位数日期
EN

Stack Overflow用户
提问于 2013-04-15 14:27:32
回答 3查看 958关注 0票数 0

我有一个日历程序,它驻留在服务器上,这个程序以这样的格式将日期存储到数据库中:

YYYYMMDD

在asp中是否有“容易”的方法来管理这些日期?例如,让我们假设2013年4月20日为日期:

代码语言:javascript
复制
20130420

我们希望将这一日期再延长20天,因此我们想要制作:

代码语言:javascript
复制
20130510

知道吗?在asp中有integerTOdate转换吗?或者我可以用什么东西把“天”加到20130420这个数字上?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-04-15 14:40:04

像这样的东西(未经测试):

代码语言:javascript
复制
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)
票数 3
EN

Stack Overflow用户

发布于 2013-04-15 14:29:41

是的,您可以使用DateAdd函数

代码语言:javascript
复制
Response.Write(DateAdd("d",1,Now()))

你需要先把你的约会安排成这样

代码语言:javascript
复制
<%
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

%>
票数 2
EN

Stack Overflow用户

发布于 2013-04-29 08:40:06

一种能够完全控制订单和格式的解决方案.

代码语言:javascript
复制
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排序要容易得多,即:易于阅读,因为所有行都有相同数目的字符,如:

代码语言:javascript
复制
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

而不是:

代码语言:javascript
复制
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:59
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16017717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档