473,386 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Formatting a datetime column

I am using .Net 2.0 and VS2005 with SQL server db. The datetime columns on
SQL have the date and time in them. How can I display just the short date
format (e.g. a datetime of 10/19/2006 11:23:57 AM to show as just
10/19/2006)? I do not want to use the SQL CONVERT on the query because it
affects the sorting of the column in a GridView. If I leave the date and
time together, I get the correct sort. Below is a sample of my textbox on
the GridView column:

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("updated_datetime")
%>'></asp:TextBox>

Thank you.

David
Oct 19 '06 #1
3 8804
Bind accepts a 2nd parameter which is the format

You can use a standard format:
http://msdn2.microsoft.com/en-us/library/az4se3k1.aspx

Bind("XXX", "{0:d}")

or a custom format:
http://msdn2.microsoft.com/en-us/library/8kb3ddd4.aspx

Bind("XXX", "{0:dd MM yyyy}")
Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"David" <dl*****@lifetimeinc.comwrote in message
news:ur**************@TK2MSFTNGP02.phx.gbl...
>I am using .Net 2.0 and VS2005 with SQL server db. The datetime columns on
SQL have the date and time in them. How can I display just the short date
format (e.g. a datetime of 10/19/2006 11:23:57 AM to show as just
10/19/2006)? I do not want to use the SQL CONVERT on the query because it
affects the sorting of the column in a GridView. If I leave the date and
time together, I get the correct sort. Below is a sample of my textbox on
the GridView column:

<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("updated_datetime") %>'></asp:TextBox>

Thank you.

David

Oct 19 '06 #2
Thanks. Do you need htmlencode="false" when you do this inside of the
BIND() ?

David

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
netwrote in message news:u4**************@TK2MSFTNGP03.phx.gbl...
Bind accepts a 2nd parameter which is the format

You can use a standard format:
http://msdn2.microsoft.com/en-us/library/az4se3k1.aspx

Bind("XXX", "{0:d}")

or a custom format:
http://msdn2.microsoft.com/en-us/library/8kb3ddd4.aspx

Bind("XXX", "{0:dd MM yyyy}")
Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"David" <dl*****@lifetimeinc.comwrote in message
news:ur**************@TK2MSFTNGP02.phx.gbl...
>>I am using .Net 2.0 and VS2005 with SQL server db. The datetime columns
on SQL have the date and time in them. How can I display just the short
date format (e.g. a datetime of 10/19/2006 11:23:57 AM to show as just
10/19/2006)? I do not want to use the SQL CONVERT on the query because it
affects the sorting of the column in a GridView. If I leave the date and
time together, I get the correct sort. Below is a sample of my textbox on
the GridView column:

<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("updated_datetime") %>'></asp:TextBox>

Thank you.

David


Oct 19 '06 #3
don't think so...

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"David" <dl*****@lifetimeinc.comwrote in message
news:en****************@TK2MSFTNGP04.phx.gbl...
Thanks. Do you need htmlencode="false" when you do this inside of the
BIND() ?

David

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
netwrote in message news:u4**************@TK2MSFTNGP03.phx.gbl...
>Bind accepts a 2nd parameter which is the format

You can use a standard format:
http://msdn2.microsoft.com/en-us/library/az4se3k1.aspx

Bind("XXX", "{0:d}")

or a custom format:
http://msdn2.microsoft.com/en-us/library/8kb3ddd4.aspx

Bind("XXX", "{0:dd MM yyyy}")
Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"David" <dl*****@lifetimeinc.comwrote in message
news:ur**************@TK2MSFTNGP02.phx.gbl...
>>>I am using .Net 2.0 and VS2005 with SQL server db. The datetime columns
on SQL have the date and time in them. How can I display just the short
date format (e.g. a datetime of 10/19/2006 11:23:57 AM to show as just
10/19/2006)? I do not want to use the SQL CONVERT on the query because
it affects the sorting of the column in a GridView. If I leave the date
and time together, I get the correct sort. Below is a sample of my
textbox on the GridView column:

<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("updated_datetime") %>'></asp:TextBox>

Thank you.

David



Oct 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
2
by: Iwan Petrow | last post by:
Hi, I have a column DateTime in a table in MS SQL Server database. I take this column using a Web Service and show it in a TextBox in a Web Application. I want the format of the date to be...
4
by: darrel | last post by:
I'm binding fileinformation to a repeater and attempting to display the 'lastWriteTime' property as a formatted date. This: <%# DataBinder.Eval(Container.DataItem, "LastWriteTime" %> Gives...
2
by: John Dann | last post by:
I've got what seems to be a common problem with the DataGrid control - I want to display a dataset one of whose columns (always the first column) is a datetime column. But only the date displays...
4
by: Alex Maghen | last post by:
If I have a DateTime column in my DataGrid conrol, and it's bound to an OleDbDataReader, how can I format the returned data the way I want it formatted and displayed in that column? Alex
4
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the...
11
by: tlyczko | last post by:
Hello, I'm new to SQL Server, working for a non-profit computerizing a lot of its data. I imported a table of people's names, birth dates, etc. into SS2005 from Access, and the birth_date was...
1
by: Untitled | last post by:
I have an application that stores all DateTime inforamtion in UTC. However, this application will be accessed from arround the world. I would like my users to be able to specify their prefered...
10
by: WebCM | last post by:
There is a function: http://paste.ubuntu.com/21865 It needs GMT date in YYYY-MM-DD HH:MM:SS format - in SQL: datetime. If date is the same as today, the function returns "Today". There is one...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.