I took this evening out to play aruond with dates n times , with regards to inserting and retrieveing and manipulating to and from a database.
fisrt things first, in a sql insert you can use Now() to put the date and time into most databases, provided that the filed is cast as a Date/Time field.
insert into mytable (‘id’,’text’,Now(),’helooo’);
so now you have a workable date in your table.
This is fine but you want to bind them to a DateTime type in .net when you read them. This allows you to do example…
to do this, simply convert the data from your data reader
//notice time field not converted to string at all, just binded straight to a DateTime
Your timestamp is now in a format ready to
- sort ( ORDER BY DATE DESC)
- add, time difference, etc