Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > returning date with two digit year

Reply
Thread Tools

returning date with two digit year

 
 
middletree
Guest
Posts: n/a
 
      07-08-2005
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.


 
Reply With Quote
 
 
 
 
Aaron Bertrand [SQL Server MVP]
Guest
Posts: n/a
 
      07-08-2005
> 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


 
Reply With Quote
 
 
 
 
middletree
Guest
Posts: n/a
 
      07-08-2005
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]" <> wrote in message
news:...
> > 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
>
>



 
Reply With Quote
 
middletree
Guest
Posts: n/a
 
      07-08-2005
"Aaron Bertrand [SQL Server MVP]" <> 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?


 
Reply With Quote
 
Dave Anderson
Guest
Posts: n/a
 
      07-08-2005
middletree wrote:
> 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.


SELECT RecordID,
CONVERT(CHAR(,EffectiveDate,1) AS EffectiveDate,
...
FROM MyTable

http://msdn.microsoft.com/library/en...ca-co_2f3o.asp



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      07-08-2005
middletree wrote on 08 jul 2005 in microsoft.public.inetserver.asp.general:

> 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.


The old straightforward basic way:

d = "05/10/2004"

d2 = left(d,6) & right(d,2)


--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
Reply With Quote
 
middletree
Guest
Posts: n/a
 
      07-11-2005
Oh wow. That is pretty basic. I never even thought of that. Thanks!


"Evertjan." <> wrote in message
news:Xns968E3063224eejj99@194.109.133.242...
> middletree wrote on 08 jul 2005 in

microsoft.public.inetserver.asp.general:
>
> > 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.

>
> The old straightforward basic way:
>
> d = "05/10/2004"
>
> d2 = left(d,6) & right(d,2)
>
>
> --
> Evertjan.
> The Netherlands.
> (Replace all crosses with dots in my emailaddress)
>



 
Reply With Quote
 
Aaron Bertrand [SQL Server MVP]
Guest
Posts: n/a
 
      07-11-2005
> But *WHY* would you do that when SQL already has the ability to give you
> the date in the format you desire?


Because many would argue that string formatting is the job of the
client/presentation tier, not the database.


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      07-11-2005
Dave Anderson wrote on 11 jul 2005 in
microsoft.public.inetserver.asp.general:

> middletree wrote:
>>> d2 = left(d,6) & right(d,2)

>>
>> Oh wow. That is pretty basic. I never even thought of that. Thanks!

>
> But *WHY* would you do that when SQL already has the ability to give
> you the date in the format you desire?
>


Because, Dave, one should have alternatives to choose from.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
Reply With Quote
 
middletree
Guest
Posts: n/a
 
      07-11-2005
I could see both sides, but ultimately, I see it the way Aaron put it. The
presentation layer is the presentation layer.

Having said that, you provided me with a bit of SQL code that I had not been
aware of, so I thank you. I am sure it will come in handy down the road.


"Dave Anderson" <> wrote in message
news:...
> middletree wrote:
> >> d2 = left(d,6) & right(d,2)

> >
> > Oh wow. That is pretty basic. I never even thought of that. Thanks!

>
> But *WHY* would you do that when SQL already has the ability to give you

the
> date in the format you desire?
>
>
>
> --
> Dave Anderson
>
> Unsolicited commercial email will be read at a cost of $500 per message.

Use
> of this email address implies consent to these terms. Please do not

contact
> me directly or ask me to contact you directly for assistance. If your
> question is worth asking, it's worth posting.
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(8-bit binary to two digit bcd) or (8-bit binary to two digit seven segment) Fangs VHDL 3 10-26-2008 06:41 AM
2-digit year dates not validated properly during client validation =?Utf-8?B?UGFuYXlvdGlzIEtvdXZhcmFraXM=?= ASP .Net 0 12-02-2005 02:17 PM
date to digit Sara Khalatbari Python 2 04-30-2005 02:26 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Date object's getDay returns wrong date for Feb in any leap year David Woodward Javascript 5 02-02-2004 08:22 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57