asp date format question

Discussion in 'ASP General' started by Lin Ma, Apr 12, 2005.

  1. Lin Ma

    Lin Ma Guest

    In my asp page, I have a date value from SQL database and I would like to be
    formatted like: yyyy,mm,dd.

    Such as 1/22/2005 to be 2005,1,22

    Is there a simple command I can use?

    Thanks,


    Lin
     
    Lin Ma, Apr 12, 2005
    #1
    1. Advertising

  2. Lin Ma

    McKirahan Guest

    "Lin Ma" <> wrote in message
    news:#...
    > In my asp page, I have a date value from SQL database and I would like to

    be
    > formatted like: yyyy,mm,dd.
    >
    > Such as 1/22/2005 to be 2005,1,22
    >
    > Is there a simple command I can use?
    >
    > Thanks,
    >
    >
    > Lin


    Will this help? Watch for word-wrap.

    strDAT = { your SQL database date }

    strDAT = DatePart("yyyy",strDAT) & "," & DatePart("d",strDAT) & "," &
    DatePart("m",strDAT)

    Note that "mm/dd/yyyy" format may be confusing and that "yyyy/mm/dd" is
    preferred.
     
    McKirahan, Apr 12, 2005
    #2
    1. Advertising

  3. Lin Ma

    dlbjr Guest

    Just for fun and faster

    Function MyDateFormat(d)
    a = Split(d,"/")
    If IsArray(a) Then
    MyDateFormat = a(2) & "," & a(0) & "," & a(1)
    End If
    End Function

    'dlbjr
    'Pleading sagacious indoctrination!
     
    dlbjr, Apr 12, 2005
    #3
  4. Lin Ma wrote:
    > In my asp page, I have a date value from SQL database and I would
    > like to be formatted like: yyyy,mm,dd.
    >
    > Such as 1/22/2005 to be 2005,1,22


    That is not an example of yyyy,mm,dd format, as you are suppressing leading
    zeroes.



    > Is there a simple command I can use?


    If you *really* want yyyy,mm,dd format, then you could let SQL do it, for
    one thing. Using date format 102, you can force the output into yyyy.mm.dd,
    then replace '.' with ',':

    SELECT REPLACE(CONVERT(CHAR(10),GETDATE(),102),'.',',')

    http://msdn.microsoft.com/library/en-us/tsqlref/ts_ca-co_2f3o.asp
    http://msdn.microsoft.com/library/en-us/tsqlref/ts_ra-rz_76lh.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.
     
    Dave Anderson, Apr 13, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Candy
    Replies:
    2
    Views:
    1,179
    Janaka
    Feb 18, 2004
  2. DC
    Replies:
    5
    Views:
    3,022
    Brendan Reynolds
    Jul 1, 2005
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,302
    Michael Borgwardt
    May 30, 2004
  4. Chu
    Replies:
    3
    Views:
    4,207
    Shawn
    Aug 15, 2006
  5. Josh Sharpe
    Replies:
    1
    Views:
    217
    Brian Candler
    Sep 21, 2010
Loading...

Share This Page