从数据中读取日期yyyy/mm/dd如何转换成yyyy-mm-dd

xzf888 2020-10-26 01:43:39
我的数据库中以<%=rs("selldate")%>读取日期后,
在页面上显示的是这个样式 yyyy/mm/dd 如何转换成 yyyy-mm-dd
和 yyyy-mm-dd hh:mm:ss 这二个格式,代码给如何写,
也就是需要得到的是2020-10-26 和 2020-10-26 13:45:54 这二种

<%=FormatDateTime(rs("selldate"),1)%> 这个转换不了我要的样式。望老师们给个详细代码。感谢!
...全文
27914 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuchao360409 2020-12-15
  • 打赏
  • 举报
回复
<%=Year(rs("selldate"))%>-<%if Month(rs("selldate"))<10 then%>0<%end if%><%=Month(rs("selldate"))%>-<%if Day(rs("selldate"))<10 then%>0<%end if%><%=Day(rs("selldate"))%>
weixin_42037497 2020-10-30
  • 打赏
  • 举报
回复
rs("selldate").ToString("yyyy-MM-dd")
hgwyl 2020-10-30
  • 打赏
  • 举报
回复
FormatDateTime的各个参数,自己试一下就好。 然后replace(变量,"-","/") <%=replace(FormatDateTime(rs("selldate"),2),"-","/"%> 2020-10-26 <%=replace(FormatDateTime(rs("selldate"),0),"-","/"%> 2020-10-26 13:45:54
lllomh 2020-10-27
  • 打赏
  • 举报
回复
建议你用js 去转换
xzf888 2020-10-27
  • 打赏
  • 举报
回复
引用 2 楼 qq_63572063 的回复:

response.write formatdate(selldate,"y-m-d")
response.write formatdate(selldate,"y-m-d h:n:s")
Function formatdate(byval sdate,byval stype)
          Dim y,m,d,h,n,s,otime
          y = Year(sdate)
          m = right("00" & Month(sdate),2)
          d = right("00" & Day(sdate),2)
          h = right("00" & Hour(sdate),2)
          n = right("00" & Minute(sdate),2)
          s = right("00" & Second(sdate),2)
          otime = stype
          otime = Replace(otime,"timestamp",DateDiff("s","1970-01-01 08:00:00",sdate))  
          otime = Replace(otime,"y",y)
          otime = Replace(otime,"m",m)
          otime = Replace(otime,"d",d)
          otime = Replace(otime,"h",h)
          otime = Replace(otime,"n",n)
          otime = Replace(otime,"s",s)
          formatdate = otime
End Function
老师能解释一下吗,我代码上去不显示了,如何完全代码这个<%=rs("selldate")%>
  • 打赏
  • 举报
回复

response.write formatdate(selldate,"y-m-d")
response.write formatdate(selldate,"y-m-d h:n:s")
Function formatdate(byval sdate,byval stype)
          Dim y,m,d,h,n,s,otime
          y = Year(sdate)
          m = right("00" & Month(sdate),2)
          d = right("00" & Day(sdate),2)
          h = right("00" & Hour(sdate),2)
          n = right("00" & Minute(sdate),2)
          s = right("00" & Second(sdate),2)
          otime = stype
          otime = Replace(otime,"timestamp",DateDiff("s","1970-01-01 08:00:00",sdate))  
          otime = Replace(otime,"y",y)
          otime = Replace(otime,"m",m)
          otime = Replace(otime,"d",d)
          otime = Replace(otime,"h",h)
          otime = Replace(otime,"n",n)
          otime = Replace(otime,"s",s)
          formatdate = otime
End Function
gqkmiss 2020-10-26
  • 打赏
  • 举报
回复
a = '1995/11/11'
b = a.replace(/\//g, '-')
console.log(b)
// 1995-11-11

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧