1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to order by Time

Discussion in 'C#' started by 1why, Oct 13, 2006.

  1. #1
    I try to use

    sql=select * from ArticleTable order by xTime

    but my time form : "3/18/2005 5:23:58 PM"

    and "order by xTime" urns very strange range :confused:

    do I have to reform all the time?

    Please help!
     
    1why, Oct 13, 2006 IP
  2. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #2
    is it a datetime type in your DB?
     
    ludwig, Oct 14, 2006 IP
  3. 1why

    1why Peon

    Messages:
    68
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i use <% =now %>
    and i save it as normal txt (type is same as article name field)
    so it looks like this "3/18/2005 5:23:58 PM" in DB
     
    1why, Oct 14, 2006 IP
  4. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #4
    you should have DATETIME type not TEXT so that you can sort it the way you need

    but now when you get the string, you need to convert it to a DATETIME value, but it'll be harder, in place of that change the data type to DATETIME
     
    ludwig, Oct 15, 2006 IP
    1why likes this.
  5. BurgerKing

    BurgerKing Active Member

    Messages:
    397
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Try:

    sql="select * from ArticleTable order by cast(xTime as datetime)"

    This converts the text value to a datetime, and sorts it as a datetime.
     
    BurgerKing, Oct 15, 2006 IP
    1why likes this.
  6. 1why

    1why Peon

    Messages:
    68
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    BurgerKing,

    Thank you so much.
    It works now.
    :)
    But
    However I also try <%=cast(rsL("xTime") as datetime)%> <-- do not work!!!
    what does it look like after CAST?
    length for xTime shall be longer than Datetime or same? :confused:

    Please help.
     
    1why, Oct 15, 2006 IP
    ludwig likes this.
  7. rkcca

    rkcca Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Cast is a SQL Server command and will not work in vb/vbscript
     
    rkcca, Oct 24, 2006 IP