3
Answers

Saving datetime in sql server and retreive rows sorted by datetime??

Photo of Christian

Christian

15y
3.7k
1

Hi
I need to have a row in my table (sql server 2008 express) and it needs to be possible to make calls to sql server like "all the products with datetime older than xxxx-xx-xx-xx.xx.xx.xxxx". How should I save the data in my table so i can use it for sorting when retreiving data? As a sql timestamp or a string? I have heard some negative talk about the sql timestamp and have not heard of nayone using it. At work we save timestamps as a string but that i db2 we are using.
Any suggestions??

Answers (3)

0
Photo of Christian
NA 24 0 15y

Its not the sql query im confused about its more about how the easiest way is to work with a datetime in C# and in sql. I need to have the dates displayed on my webpage but I also need to use the dates for sorting in my sql queries. I coul dsave the datetime as a string in db so it would be easy to retreive it and display it but im just not sure if I would be able to sort with it since its a string in my db. Then I need to save it as a timestamp in the db but I just want to make sure that sql timestamp is easy to work with and easy to convert into string when i want it in my c# code.
0
Photo of Lalit M
NA 6.7k 48k 15y
try this code retreive rows sorted by datetime

SELECT orderID, DATEPART(MM,OrderDate) AS OrderMonth FROM Orders

more info

http://www.sqlmag.com/article/articleid/43488/43488.html
0
Photo of Amit Choudhary
NA 27.7k 3m 15y
hi friend,

Simply using DateTime data type in sqlserver can solve your problem.


Please mark the anser if it helps.