返回日期为两位数年份 [英] returning date with two digit year

查看:93
本文介绍了返回日期为两位数年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以日期/时间格式存储在SQL Server中的字段。在一个

页面上,我只需要显示日期。我可以这样说:


DateValue(strLastModified)


但是,这会以这种格式返回给我: br />

05/10/2004


相反,我想看看:


05 / 10/04,但我不知道该怎么做。

解决方案

> 05/10/2004


相反,我想看看:

05/10/04,但我不知道该怎么做。




我可以问你为什么要这些格式?两者都不明确,

和你喜欢的那个比你现在使用的那个更多。


05/10/2004 - 是5月10日还是10月5日?取决于你在哪个国家

进/出...


05/10/04 - 这可能是几乎任何事情,2004年5月10日,10月5月

2004年,2005年10月4日...


无论如何,当然创建自己的格式为
$ b的函数是微不足道的$ b日期,但你想要它。你没有提供你的特定格式,但它应该花费大约四秒钟来调整其中一个样本:

http://www.aspfaq.com/2313


就个人而言,我试图坚持YYYY-MM-DD表示所有显示值,

YYYYMMDD表示传递给数据库的所有值。


A


好问题。我遵循老板的命令,这是一个基于内联网的应用程序,因此只有某些人会看到它。老板要我挤几栏,但他仍然希望它足够窄,以便在不滚动的情况下适应屏幕。
有一页

/>

我应该在我发布问题之前添加它,我会在其他地方查找,

包括您的网站和Microsoft,以及我的MSDN库。但是我没有发现任何预制功能

。我认为它是一个,我会在这里听到它,

如果没有,我会摆弄正确的功能。


Aaron Bertrand [SQL Server MVP]" < TE ***** @ dnartreb.noraa>在消息中写道

news:Op ************* @ TK2MSFTNGP14.phx.gbl ...

05/10/2004

相反,我希望看到:

05/10/04,但我不知道该怎么做。
我可以问你为什么要这些格式?两者都含糊不清,而且你喜欢的那个比你现在使用的那个更多。

05/10/2004 - 是5月10日,还是10月5?取决于你所在的国家



...

05/10/04 - 这可能是几乎任何事情,2004年5月10日,10月2004年第5期,2005年10月4日...

无论如何,当然创建自己的函数是很简单的,可以按照你想要的日期格式化
。你没有提供你的特定格式,但是b b $ b需要大约4秒来调整其中一个样本:

http://www.aspfaq.com/2313

我个人试着坚持使用YYYY-MM-DD显示值,并为所有传递给数据库的值显示YYYYMMDD。



Aaron Bertrand [SQL Server MVP] < TE ***** @ dnartreb.noraa>在消息中写道

您的特定格式不提供,但它应该花费大约四秒钟来调整其中一个样本:

http://www.aspfaq.com/2313



嗯。我第一次看到这篇文章,但是我真的不明白

如何使用示例代码。对于我想要的格式,我发现了这个:


<%

response.write pd(DAY(date()),2)& " - " &安培; _

pd(月(日()),2)& " - " &安培; _

pd(正确(年(日期()),2),2)

%>


当然,只需要用斜线替换连字符。但我真的不知道如何使用这段代码。是否需要

页面顶部的代码段?


I have a field that is stored in SQL Server in date/time format. On one
page, I only need the date to display. I am able to do this by saying:

DateValue(strLastModified)

However, this returns to me the date in this format:

05/10/2004

Instead, I would like to see:

05/10/04, but I am not sure how to do this.

解决方案

> 05/10/2004


Instead, I would like to see:

05/10/04, but I am not sure how to do this.



Can I ask why you would like either of these formats? Both are ambiguous,
and the one you''d prefer is more so than the one you''re currently using.

05/10/2004 - is that May 10th, or October 5th? Depends on what country you
are in/from...

05/10/04 - this could be just about anything, May 10th 2004, October 5th
2004, October 4th 2005...

Anyway, of course it is trivial to create your own functions that format the
date however you want it. Your specific format isn''t offered, but it should
take about four seconds to adapt one of the samples:

http://www.aspfaq.com/2313

Personally, I try to stick with YYYY-MM-DD for all display values, and
YYYYMMDD for all values that are passed to a database.

A


Good questions. I am following the orders of my boss, and this is an
Intranet-based app, so only certain people will see it. There''s one page
that the boss wants me to squeeze several columns on, yet he still wants it
narrow enough to fit onto the screen without scrolling.

I should add that before I post a question here, I do look elsewhere,
including your site and Microsoft, plus my MSDN library. But I didn''t find
any pre-made function. I figured it fhter was one, I''d hear about it here,
and if not, I''d fiddle with the Right function.

"Aaron Bertrand [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:Op*************@TK2MSFTNGP14.phx.gbl...

05/10/2004

Instead, I would like to see:

05/10/04, but I am not sure how to do this.
Can I ask why you would like either of these formats? Both are ambiguous,
and the one you''d prefer is more so than the one you''re currently using.

05/10/2004 - is that May 10th, or October 5th? Depends on what country


you are in/from...

05/10/04 - this could be just about anything, May 10th 2004, October 5th
2004, October 4th 2005...

Anyway, of course it is trivial to create your own functions that format the date however you want it. Your specific format isn''t offered, but it should take about four seconds to adapt one of the samples:

http://www.aspfaq.com/2313

Personally, I try to stick with YYYY-MM-DD for all display values, and
YYYYMMDD for all values that are passed to a database.

A



"Aaron Bertrand [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message

Your specific format isn''t offered, but it should
take about four seconds to adapt one of the samples:

http://www.aspfaq.com/2313



Hmm. I saw this article the first time around, but didn''t really understand
how to use the sample code. For the format I want, I found this:

<%
response.write pd(DAY(date()),2) & "-" & _
pd(MONTH(date()),2) & "-" & _
pd(RIGHT(YEAR(date()),2),2)
%>

Of course, just need to replace the hyphen with a slash. But I don''t really
get how to use this code. Does it require the code snippet at the top of the
page?


这篇关于返回日期为两位数年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆