Date format is different in 2 gridviews

Discussion in 'ASP .Net' started by Hennie, Jul 11, 2006.

  1. Hennie

    Hennie Guest

    I have 2 gridviews on a page, each with own SQL Datasource pointing to
    different tables on same database.
    In the 1st date format is "dd/MM/yyyy"
    Other 1
    "MM/dd/yyyy hh:mm:ss"

    In the SQL database both fields are data type DateTime.
    I want both to be in format "dd/MM/yyyy"
    Why is the display different, and how can I get them the same?

    Thanks
     
    Hennie, Jul 11, 2006
    #1
    1. Advertising

  2. I'm not sure why they are displaying differently, but you can Edit
    Columns on each and set the format to {0:d} to get the short date
    format you want. The only caveat is that you also have to set the
    HTMLEncode value to false for the format property to be observed. I've
    read that doing so might expose some sort of security risk, but I don't
    know the nature or level of severity.

    HTH,
    Rich

    Hennie wrote:
    > I have 2 gridviews on a page, each with own SQL Datasource pointing to
    > different tables on same database.
    > In the 1st date format is "dd/MM/yyyy"
    > Other 1
    > "MM/dd/yyyy hh:mm:ss"
    >
    > In the SQL database both fields are data type DateTime.
    > I want both to be in format "dd/MM/yyyy"
    > Why is the display different, and how can I get them the same?
    >
    > Thanks
     
    Richard Carpenter, Jul 11, 2006
    #2
    1. Advertising

  3. Hennie

    tfsmag Guest

    You can also specify in your stored proc or ad hoc query how the
    database spits out the date format. on the column for the date in the
    select clause you can do like so

    select
    convert(char(10),the_date_field,101) as the_date_field
    from tablename

    this should format the date as a mm/dd/yyyy


    Richard Carpenter wrote:
    > I'm not sure why they are displaying differently, but you can Edit
    > Columns on each and set the format to {0:d} to get the short date
    > format you want. The only caveat is that you also have to set the
    > HTMLEncode value to false for the format property to be observed. I've
    > read that doing so might expose some sort of security risk, but I don't
    > know the nature or level of severity.
    >
    > HTH,
    > Rich
    >
    > Hennie wrote:
    > > I have 2 gridviews on a page, each with own SQL Datasource pointing to
    > > different tables on same database.
    > > In the 1st date format is "dd/MM/yyyy"
    > > Other 1
    > > "MM/dd/yyyy hh:mm:ss"
    > >
    > > In the SQL database both fields are data type DateTime.
    > > I want both to be in format "dd/MM/yyyy"
    > > Why is the display different, and how can I get them the same?
    > >
    > > Thanks
     
    tfsmag, Jul 11, 2006
    #3
    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,207
    Janaka
    Feb 18, 2004
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,374
    Michael Borgwardt
    May 30, 2004
  3. Chu
    Replies:
    3
    Views:
    4,238
    Shawn
    Aug 15, 2006
  4. Replies:
    1
    Views:
    820
    mlimber
    Sep 11, 2006
  5. Josh Sharpe
    Replies:
    1
    Views:
    228
    Brian Candler
    Sep 21, 2010
Loading...

Share This Page