Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2002
    Posts
    4

    Unanswered: A simple date problem?

    using the date function in asp is supposed to give me the date as mm/dd/yyyy.
    But for example today 24 march 2003 comes out as 3/24/2003.
    but what I would like is it to come out as 03/24/2003.

    The reason being when I store this into a sql database and sort it using a sql statement say by ascending order ,it comes out as

    1/20/02
    10/20/02
    11/20/02
    12/20/02
    2/20/02
    3/20/02

    instead of

    1/20/02
    2/20/02
    3/20/02
    10/20/02
    11/20/02
    12/20/02

    Any suggestions will be greatly appreciated .
    Thanks a lot .

  2. #2
    Join Date
    Mar 2003
    Posts
    8

    Try this

    Dim month_string,day_string,year_string,date_string

    month_string=month(date)
    if len(month_string)=1 then
    month_string="0" & month_string
    end if

    day_string=day(date)
    if len(day_string)=1 then
    day_string="0" & day_string
    end if


    year_string=right(year(date),2)
    date_string=month_string & "/" & day_string & "/" & year_string

    'Now you use date_string

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    > The reason being when I store this into a sql database
    > and sort it using a sql statement say by ascending order,
    > it comes out as ...

    no

    dates are stored in databases as some humungous integer measuring the number of days from january 1, 0000 or some other base date

    dates are always converted, both going into a database (being stored) and coming out (being queried)

    so if you are not getting the right display format on dates that you are querying, then you must change the way you format the date in the SELECT (you could also do it in ASP, i suppose, but it's much easier to do it in the SELECT)

    if you are using Microsoft Access, check out the FORMAT function in the help

    if you are using SQL Server, see CAST and CONVERT

    you will probably want CONVERT(char(10),yourdate,101)

    be careful sorting on it, because it is a string, and 03/24/2003 will come before 12/31/1999

    you may want to keep yourdate in the SELECT list as well, and sort on that


    rudy
    http://rudy.ca/

  4. #4
    Join Date
    Feb 2002
    Location
    San Francisco, CA
    Posts
    441
    look up the set locale thing: you can change the date format using that. if not use formatdate()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •