DateTime Problem

T

Tina

I'm selecting some columns using a .net dataadapter using Select myDate from
myTable. then I...
DIM dt as new datatable
myda.fill(dt)

Now in dubugging I am examining the dt.rows(0).ItemArray (because I didn't
trust what was displaying in my datagrid)

It shows my date as being 8/31/2005 1:26:45 PM. The problem is that the
real date in the database is 8/31/2005 1:26:45:197 PM !!!

Something in the data adapter or something somewhere else is cutting off the
197.

This is a big problem for me because I use this date later in a where clause
for an update and the lack of the 197 is causing the where to fail.

Why is the 197 being cutoff? What can I do about this?

Thanks,
T
 
R

Robbe Morris [C# MVP]

I'm pretty sure if that is being loaded into a .NET DateTime class,
it is still there. You just need to perform the proper formatting.
I don't recall what the milliseconds option is. You'll have
to look that up. It might be "hh:mm:ss:sss". Can't remember.

The following is a sample that formats the date as dd-MMM-yy.

DateTime myDate = (DateTime)dt.Rows[0]["MyDataColumn"];

Console.WriteLine(myDate.ToString("dd,MMM,yy").Replace(",","-"));
 
C

Cor Ligthert [MVP]

Tina,

In addition to Robbe
It shows my date as being 8/31/2005 1:26:45 PM. The problem is that the
real date in the database is 8/31/2005 1:26:45:197 PM !!!
The VS IDE is showing dates and times at the moment only in USA format
whatever culturesetting you have in your computer. This is not the
representation of the real dates and times. How the dateTime is stored is
dependable from the brand of the database.

However every internally DateTime in .Net is stored in ticks representing a
unit of 100 nanoseconds starting at 01-01-01.

In SQL server it are milliseconds starting with a smalldate at 1-1-1900 and
with a normal datetime at 1753 (the begin of the Georgian Calendar in the
British Empire which was the last in that. Therefore the only precise start
date in any culture when that calendar is used is that date)

There are more formats, however maybe I help you to overcome some confusions
with date and times.

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top