Date Format

Date Format

am 25.01.2008 18:58:01 von TomNowak

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.

RE: Date Format

am 25.01.2008 20:00:00 von brucebarker

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.

Re: Date Format

am 25.01.2008 20:05:52 von mark

"Tom Nowak" wrote in message
news:39554ACD-7814-4AB4-A878-F6BB5B447002@microsoft.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...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

RE: Date Format

am 25.01.2008 21:49:08 von TomNowak

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.

Re: Date Format

am 25.01.2008 21:53:54 von mark

"Tom Nowak" wrote in message
news:94AD7F4B-D816-49B1-96EE-D96238F33B95@microsoft.com...

> 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

Re: Date Format

am 25.01.2008 22:06:04 von TomNowak

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:94AD7F4B-D816-49B1-96EE-D96238F33B95@microsoft.com...
>
> > 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
>
>

Re: Date Format

am 25.01.2008 23:14:28 von mark

"Tom Nowak" wrote in message
news:8810A533-B2A5-4524-A58E-D3A7F3A1A6F0@microsoft.com...

>> > 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

Re: Date Format

am 26.01.2008 18:34:16 von gnewsgroup

On Jan 25, 5:14 pm, "Mark Rae [MVP]" wrote:
> "Tom Nowak" wrote in message
>
> news:8810A533-B2A5-4524-A58E-D3A7F3A1A6F0@microsoft.com...
>
>
>
> >> > 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.

Re: Date Format

am 26.01.2008 18:45:39 von mark

"gnewsgroup" wrote in message
news:274cb056-762e-46d4-9893-b2588cbea0ba@q21g2000hsa.google groups.com...

>> 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

Re: Date Format

am 26.01.2008 20:40:01 von gnewsgroup

On Jan 26, 12:45 pm, "Mark Rae [MVP]" wrote:
> "gnewsgroup" wrote in message
>
> news:274cb056-762e-46d4-9893-b2588cbea0ba@q21g2000hsa.google groups.com...
>
> >> 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?

Re: Date Format

am 26.01.2008 20:58:33 von mark

"gnewsgroup" wrote in message
news:131e9a9e-cedf-499b-85b0-7bdac174ba43@l1g2000hsa.googleg roups.com...

>> >> 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

Re: Date Format

am 26.01.2008 21:11:24 von gnewsgroup

On Jan 26, 2:58 pm, "Mark Rae [MVP]" wrote:
> "gnewsgroup" wrote in message
>
> news:131e9a9e-cedf-499b-85b0-7bdac174ba43@l1g2000hsa.googleg roups.com...
>
> >> >> 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?

Re: Date Format

am 26.01.2008 21:19:10 von mark

"gnewsgroup" wrote in message
news:63d0bd6f-f078-4b82-97d2-debdd4446a99@s8g2000prg.googleg roups.com...

>> 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

Re: Date Format

am 26.01.2008 21:32:03 von gnewsgroup

On Jan 26, 3:19 pm, "Mark Rae [MVP]" wrote:
> "gnewsgroup" wrote in message
>
> news:63d0bd6f-f078-4b82-97d2-debdd4446a99@s8g2000prg.googleg roups.com...
>
> >> 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. :-)

Re: Date Format

am 27.01.2008 02:22:58 von mark

"gnewsgroup" wrote in message
news:8b5fbc60-2e8e-420f-aa2f-efd20806f27e@1g2000hsl.googlegr oups.com...

>> >> 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