Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i have problem with Data format
i try to select i rank of 2 data
i try this format of data
yyyy/mm/dd
mm/dd/yyyy
dd/mm/yyyy
but no one of this is universal for all windows machin
can some one suggest me how is the best format ?thnx
Posted
Comments
Nelek 16-Apr-12 16:44pm    
Nika, I have moved your message to a comment for chris. Please don't write answers to speak with someone that proposed you a solution. The correct way to do it is using the "improve question" if you want to add information about the problem or the button "have a question or comment?" to speak directly with the person you want (as I am doing right now with you and as I did with your comment to Chris)

If you're doing the sorting in the access database, you should be using a DateTime column type, and the database will take care of proper sorting for you.

If you're doing the sorting in your C# app, the DateTime structure has comparison operators that you can use to rank order dates.

You should use this structure, not strings, for comparing and sorting dates.

If you are displaying dates in a column in a list or grid, then it is likely that you can configure the grid to accept DateTime objects in that column (i.e. you do NOT need to convert the DateTime to a string; in fact, this may be done automatically for you). The grid will likely have a means by which you configure what part of the DateTume is actually shown to the user, and how it is formatted, but, behind the scenes, the grid knows that the datatype stored in the column is really a DateTime and therefore knows how to sort it properly.

The bottom line: only convert dates & times to strings at the very last minute; do all computing using a strongly typed variable before converting to a human readable form.

Hope that helps,
Chris
 
Share this answer
 
Comments
Nelek 16-Apr-12 16:41pm    
Comment from the OP to you Chris:
the problem is not in sort, problem i in select between 2 data`s?
for example
select *
from tabel
where tabel.data >= #dd/mm/yyyy# AND table.data <= #dd/mm/yyyy#

i cant do one query for all windows machine ???
thnx alot Chris
Chris Ross 2 17-Apr-12 5:31am    
Please forgive me for misunderstanding your difficulty!

This appears to be a matter of understanding MS Access and how it interprets date literals. You'll have to dig into the MS Access documentation to discover that.

You should also read about "parameterised queries" - the approved means of supplying parameters to SQL queries when accessing a database from C#. Using parameterised queries means that you won't have to format your dates as a string - the database access layer of the .Net runtime does that for you (you supply your DateTime C# object(s) as the value to the query's parameter(s)).

Now - I've not used MS Access from a .Net app so I'm making a big assumption that what I can do against MS SqlServer is closely analogous to what you can do with MS Access. Hopefully that's not an invalid assumption!
SQL
select *
from tabel
where tabel.data >= #dd/mm/yyyy# AND table.data <= #dd/mm/yyyy#


use BETWEEN to get data between dates.

SQL
SELECT *
FROM tabel
WHERE tabel.data BETWEEN #dd/mm/yyyy# AND #dd/mm/yyyy#
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900