472,345 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

smalldatetime and sorting

Hello all and thank you for your time.

I have a datagrid where I want to view dates (smalldatetime) and be
able to sort on the field. However, I do not want to have the time
part show. If I use the convert function(convert(char,ProjDate,101) as
ProjDate) the field is then a char and does not sort correctly.

Any solutions?

Thanks again,
Sunshine

Jul 23 '05 #1
3 3112

<su************@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hello all and thank you for your time.

I have a datagrid where I want to view dates (smalldatetime) and be
able to sort on the field. However, I do not want to have the time
part show. If I use the convert function(convert(char,ProjDate,101) as
ProjDate) the field is then a char and does not sort correctly.

Any solutions?

Thanks again,
Sunshine


I don't know much about datagrids, but you might find it easier to do this
in the datagrid, not the server. To get dates to sort correctly using
CONVERT(), you would have to do something like this (there may be other
formats which work too):

convert(char(8), ProjDate, 112)

That will always sort correctly, but it may not be in the format your users
want or expect, especially if you need to support international locations
with different locales. In general, any sort of formatting and presentation
is best done in the front end, and that's especially true of things that
depend on a user's locale, so I would investigate what you can do in the
datagrid itself.

Simon
Jul 23 '05 #2
I ended up just pulling the data as a smalldatetime anyway. In the
datagrid column, I used {0:MM/dd/yyyy} to format the date and it works
fine.

Sunshine

Jul 23 '05 #3
(su************@yahoo.com) writes:
I ended up just pulling the data as a smalldatetime anyway. In the
datagrid column, I used {0:MM/dd/yyyy} to format the date and it works
fine.


I don't know the datagrid, but you should really just set up the date
format according to the regional settings in Windows, and not hard-code a
format. (And if you hard-code a format, you should use YYYY-MM-DD and
not one that is likely to misunderstood in most countries in the world.)
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #4

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

Similar topics

1
by: Joey Martin | last post by:
How do I convert an nvarchar field to smalldatetime format? My nvarcharfield (saledatetext) is in the format YYYY-MM-DD. I want to convert is...
2
by: Joey Martin | last post by:
Please help. I have a ms sql table called data. Two fields, saledate(smalldatetime),saledatetext(nvarchar) I have dates (ex. 05/04/05) in the...
7
by: Marc Pelletier | last post by:
Hello, I have a table with a Day field, defined as smalldatetime. I am filling it from a CSharp application with the following code: DataRow r =...
7
by: Bostonasian | last post by:
I have a table that contains transactional data. Such as site view by whom, when, which template, etc, etc... Everytime when I pulled the report,...
2
by: Marc Pelletier | last post by:
Hello all, I have a library of datetime routines that make things simpler for me. Before I discovered DateTime.MinValue I had a function that...
2
by: Salim Afþar | last post by:
Hi, How can I cast from datetime type to smalldatetime type. I get the records from a table which has got a datetime type column but I want to...
2
by: .Net Sports | last post by:
I'm using these to assign a variable to a smalldatetime object in sql server: dim todnews = DateTime.Today.ToString ( "d" ) 'connection string...
5
by: Dimitri Furman | last post by:
This looks like a bug - hopefully somebody can explain what is actually happening. Using SQL Server 2000 SP4. Here's a repro script with...
6
by: SQL Server | last post by:
I've been working this for a while. Kind of new to SQL Server functions and not seeing what I am doing wrong. I have this function CREATE...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

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.