Date Format

  • Thread starter Thread starter Tom Nowak
  • Start date Start date
T

Tom Nowak

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.
 
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)
 
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...
 
So, if my query is:

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

How do I modify this statement?
 
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.

Mark Rae said:
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...?
 
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"
 
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"

Or if it is gonna be printed on a Label or Literal control, use
ToShortDateString() method.
 
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... :-)
 
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. :-)
 
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
 
Back
Top