Date Format

Discussion in 'ASP .Net' started by Tom Nowak, Jan 25, 2008.

  1. Tom Nowak

    Tom Nowak Guest

    I am saving a field to a SQL 2005 Express database in DateTime Format. I do
    not want the 12:00:00 AM to appear at the end of this data, I just want the
    Date to appear. How do I do this? Please help. Thanks.
     
    Tom Nowak, Jan 25, 2008
    #1
    1. Advertising

  2. Tom Nowak

    bruce barker Guest

    when you select the date, convert it to a string of the format of your
    choice. you can do it on the sql select or in your code behind.

    select convert(varchar,mydate,101) as mydate
    from mytable

    note: sqlserver 2008 will have a date datatype that only holds the date.

    -- bruce (sqlwork.com)


    "Tom Nowak" wrote:

    > I am saving a field to a SQL 2005 Express database in DateTime Format. I do
    > not want the 12:00:00 AM to appear at the end of this data, I just want the
    > Date to appear. How do I do this? Please help. Thanks.
     
    bruce barker, Jan 25, 2008
    #2
    1. Advertising

  3. "Tom Nowak" <> wrote in message
    news:...

    >I am saving a field to a SQL 2005 Express database in DateTime Format. I
    >do
    > not want the 12:00:00 AM to appear at the end of this data, I just want
    > the
    > Date to appear. How do I do this? Please help. Thanks.


    Not sure what you mean...

    The "12:00:00 AM" is just part of SQL Server's default presentation format
    for dates according to the locale you chose when you installed it and/or the
    locale of the OS that it's running on.

    Internally, dates are stored as numbers - the presentation is irrelevant...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Jan 25, 2008
    #3
  4. Tom Nowak

    Tom Nowak Guest

    So, if my query is:

    SELECT [id], [date], [time], [employee] FROM [changes] WHERE ([date] = @date)

    How do I modify this statement?

    "bruce barker" wrote:

    > when you select the date, convert it to a string of the format of your
    > choice. you can do it on the sql select or in your code behind.
    >
    > select convert(varchar,mydate,101) as mydate
    > from mytable
    >
    > note: sqlserver 2008 will have a date datatype that only holds the date.
    >
    > -- bruce (sqlwork.com)
    >
    >
    > "Tom Nowak" wrote:
    >
    > > I am saving a field to a SQL 2005 Express database in DateTime Format. I do
    > > not want the 12:00:00 AM to appear at the end of this data, I just want the
    > > Date to appear. How do I do this? Please help. Thanks.
     
    Tom Nowak, Jan 25, 2008
    #4
  5. "Tom Nowak" <> wrote in message
    news:...

    > So, if my query is:
    >
    > SELECT [id], [date], [time], [employee] FROM [changes] WHERE ([date] =
    > @date)
    >
    > How do I modify this statement?


    Are you really only interested in the way the date is displayed in SQL Query
    Analyzer, or are you talking about changing the presentation of the date
    when displayed on a web page...?


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Jan 25, 2008
    #5
  6. Tom Nowak

    Tom Nowak Guest

    This is my query defined to an SQLDataAdapter. When the web page displays,
    the date column contains the date and a time of 12:00:00. I dont want this
    time displayed as I have time displayed in another column.

    "Mark Rae [MVP]" wrote:

    > "Tom Nowak" <> wrote in message
    > news:...
    >
    > > So, if my query is:
    > >
    > > SELECT [id], [date], [time], [employee] FROM [changes] WHERE ([date] =
    > > @date)
    > >
    > > How do I modify this statement?

    >
    > Are you really only interested in the way the date is displayed in SQL Query
    > Analyzer, or are you talking about changing the presentation of the date
    > when displayed on a web page...?
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
     
    Tom Nowak, Jan 25, 2008
    #6
  7. "Tom Nowak" <> wrote in message
    news:...

    >> > So, if my query is:
    >> >
    >> > SELECT [id], [date], [time], [employee] FROM [changes] WHERE ([date] =
    >> > @date)
    >> >
    >> > How do I modify this statement?

    >>
    >> Are you really only interested in the way the date is displayed in SQL
    >> Query
    >> Analyzer, or are you talking about changing the presentation of the date
    >> when displayed on a web page...?

    >
    > This is my query defined to an SQLDataAdapter. When the web page
    > displays,
    > the date column contains the date and a time of 12:00:00. I dont want
    > this
    > time displayed as I have time displayed in another column.


    That's what I suspected. This has nothing whatever to do with either SQL
    Server or with your query...

    What you need to do is to change the way the data is presented to the user
    on the web page, not how it's fetched from the database.

    How you do this will depend what control you're using to display the data.
    You mention "another column", so I'm guessing you're using a GridView...?

    In which case, just add the following to the date column:

    DataFormatString="{0:ddd dd MMM yyyy}" HtmlEncode="false"


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Jan 25, 2008
    #7
  8. Tom Nowak

    gnewsgroup Guest

    On Jan 25, 5:14 pm, "Mark Rae [MVP]" <> wrote:
    > "Tom Nowak" <> wrote in message
    >
    > news:...
    >
    >
    >
    > >> > So, if my query is:

    >
    > >> > SELECT [id], [date], [time], [employee] FROM [changes] WHERE ([date] =
    > >> > @date)

    >
    > >> > How do I modify this statement?

    >
    > >> Are you really only interested in the way the date is displayed in SQL
    > >> Query
    > >> Analyzer, or are you talking about changing the presentation of the date
    > >> when displayed on a web page...?

    >
    > > This is my query defined to an SQLDataAdapter. When the web page
    > > displays,
    > > the date column contains the date and a time of 12:00:00. I dont want
    > > this
    > > time displayed as I have time displayed in another column.

    >
    > That's what I suspected. This has nothing whatever to do with either SQL
    > Server or with your query...
    >
    > What you need to do is to change the way the data is presented to the user
    > on the web page, not how it's fetched from the database.
    >
    > How you do this will depend what control you're using to display the data.
    > You mention "another column", so I'm guessing you're using a GridView...?
    >
    > In which case, just add the following to the date column:
    >
    > DataFormatString="{0:ddd dd MMM yyyy}" HtmlEncode="false"
    >
    > --
    > Mark Rae
    > ASP.NET MVPhttp://www.markrae.net


    Or if it is gonna be printed on a Label or Literal control, use
    ToShortDateString() method.
     
    gnewsgroup, Jan 26, 2008
    #8
  9. "gnewsgroup" <> wrote in message
    news:...

    >> In which case, just add the following to the date column:
    >>
    >> DataFormatString="{0:ddd dd MMM yyyy}" HtmlEncode="false"

    >
    > Or if it is gonna be printed on a Label or Literal control, use
    > ToShortDateString() method.


    Why?


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Jan 26, 2008
    #9
  10. Tom Nowak

    gnewsgroup Guest

    On Jan 26, 12:45 pm, "Mark Rae [MVP]" <> wrote:
    > "gnewsgroup" <> wrote in message
    >
    > news:...
    >
    > >> In which case, just add the following to the date column:

    >
    > >> DataFormatString="{0:ddd dd MMM yyyy}" HtmlEncode="false"

    >
    > > Or if it is gonna be printed on a Label or Literal control, use
    > > ToShortDateString() method.

    >
    > Why?
    >
    > --
    > Mark Rae
    > ASP.NET MVPhttp://www.markrae.net


    I thought that ToShortDateString() method will give you a date pattern
    like what he wanted: MM/DD/YYYY, right?
     
    gnewsgroup, Jan 26, 2008
    #10
  11. "gnewsgroup" <> wrote in message
    news:...

    >> >> In which case, just add the following to the date column:

    >>
    >> >> DataFormatString="{0:ddd dd MMM yyyy}" HtmlEncode="false"

    >>
    >> > Or if it is gonna be printed on a Label or Literal control, use
    >> > ToShortDateString() method.

    >>
    >> Why?

    >
    > I thought that ToShortDateString() method will give you a date pattern
    > like what he wanted: MM/DD/YYYY, right?


    So, what date does 03/02/2008 represent?


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Jan 26, 2008
    #11
  12. Tom Nowak

    gnewsgroup Guest

    On Jan 26, 2:58 pm, "Mark Rae [MVP]" <> wrote:
    > "gnewsgroup" <> wrote in message
    >
    > news:...
    >
    > >> >> In which case, just add the following to the date column:

    >
    > >> >> DataFormatString="{0:ddd dd MMM yyyy}" HtmlEncode="false"

    >
    > >> > Or if it is gonna be printed on a Label or Literal control, use
    > >> > ToShortDateString() method.

    >
    > >> Why?

    >
    > > I thought that ToShortDateString() method will give you a date pattern
    > > like what he wanted: MM/DD/YYYY, right?

    >
    > So, what date does 03/02/2008 represent?
    >
    > --
    > Mark Rae
    > ASP.NET MVPhttp://www.markrae.net


    That must depends on the Locale setting of the application, right?
     
    gnewsgroup, Jan 26, 2008
    #12
  13. "gnewsgroup" <> wrote in message
    news:...

    >> So, what date does 03/02/2008 represent?

    >
    > That must depend on the Locale setting of the application, right?


    Correct or, more specifically, it will depend on the locale setting of the
    webserver on which the web application is running, which means that it's
    *ALWAYS* the wrong format for a web application...

    It's a big ol' world, you know... :)


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Jan 26, 2008
    #13
  14. Tom Nowak

    gnewsgroup Guest

    On Jan 26, 3:19 pm, "Mark Rae [MVP]" <> wrote:
    > "gnewsgroup" <> wrote in message
    >
    > news:...
    >
    > >> So, what date does 03/02/2008 represent?

    >
    > > That must depend on the Locale setting of the application, right?

    >
    > Correct or, more specifically, it will depend on the locale setting of the
    > webserver on which the web application is running, which means that it's
    > *ALWAYS* the wrong format for a web application...
    >
    > It's a big ol' world, you know... :)
    >
    > --
    > Mark Rae
    > ASP.NET MVPhttp://www.markrae.net


    Then, the only thing I can think of is to manipulate it in the code
    depending on where the query is coming from. Or, to be lazy, let the
    end user decide on it. :)
     
    gnewsgroup, Jan 26, 2008
    #14
  15. "gnewsgroup" <> wrote in message
    news:...

    >> >> So, what date does 03/02/2008 represent?

    >>
    >> > That must depend on the Locale setting of the application, right?

    >>
    >> Correct or, more specifically, it will depend on the locale setting of
    >> the
    >> webserver on which the web application is running, which means that it's
    >> *ALWAYS* the wrong format for a web application...
    >>
    >> It's a big ol' world, you know... :)

    >
    > Then, the only thing I can think of is to manipulate it in the code
    > depending on where the query is coming from. Or, to be lazy, let the
    > end user decide on it. :)


    You're joking, obviously - for one thing, you can never reliably know where
    the query "is coming from"...

    And, just as likely,-the user could be travelling overseas on business and
    visiting your site from an Internet cafe at an airport...

    The only thing I can think of is to not use an unambiguous date format e.g.
    dd MMM yyyy


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Jan 27, 2008
    #15
    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,172
    Janaka
    Feb 18, 2004
  2. DC
    Replies:
    5
    Views:
    3,010
    Brendan Reynolds
    Jul 1, 2005
  3. Peter Grison

    Date, date date date....

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

Share This Page