problem with date types

R

Rob T

I'm storing a date/time into a SQL table of type datetime. I need it to be
precise so the value is stored to the 1000th of a second. ie "insert into
myTable mydate values ('08/05/2005 2:56:11.987'). This works fine...if you
check the value in the table with query analyzer, it shows in there
properly.

Now, in my app, I'm executing the same query (that I used in QA) and storing
tha in a dataview. If I break and watch the program, the value that's
stored in the dataview is #8/5/2005 2:56:11 PM# with a datatype of
date....so it's truncating my fractions of a second!!!

How can I get my missing time? Thanks.
 
T

Tom.PesterDELETETHISSS

Mabye this hack will help you furhter. Try to cast the date to a string on
sql server so once its passed to asp.net it will accept the data as a whole
and not interpret it.

I hope it helps...

Cheers,
Tom Pester
 
H

Herfried K. Wagner [MVP]

Rob T said:
I'm storing a date/time into a SQL table of type datetime. I need it to
be precise so the value is stored to the 1000th of a second. ie "insert
into myTable mydate values ('08/05/2005 2:56:11.987'). This works
fine...if you check the value in the table with query analyzer, it shows
in there properly.

Now, in my app, I'm executing the same query (that I used in QA) and
storing tha in a dataview. If I break and watch the program, the value
that's stored in the dataview is #8/5/2005 2:56:11 PM# with a datatype of
date....so it's truncating my fractions of a second!!!

Make sure you read the "Remarks" section of the "'DateTime' structure"
chapter of the documentation.
 
R

Rob T

I assume you're referring to the fact that the datetime only goes to the
nearest second...or am I missing something? I was hoping that when the
datastructure of the dv was created that I could store it as a string....?
 
C

Cor Ligthert [MVP]

Rob,

Are you sure of that, what you see is the US representation (which make
people outside that sometimes crazy) in the IDE.

The dateTime itself is a format in long, containing ticks starting at the
year that the Georgian Calendar started to be used in England (and therefore
in its colonies from which the US was one at that time).

I hope this helps,

Cor
 
R

Rob T

(head spinning) I just wanted to know how I can get a date field with
fractions of a second into my dataview..........

-Regards from New England!
 
A

Armin Zingler

Rob T said:
(head spinning) I just wanted to know how I can get a date field
with fractions of a second into my dataview..........


In your dataview, you don't have any information stored. Probably a
datatable stores it. This also includes the fractions of a second. Your
problem is probably converting the value into a string including the
fractions.

We don't know how you convert the value or have it converted to a string,
thus it's hard to give a suggestion. If you use the Date's ToString method,
have a look at the ToString function's documentation how to include the
fractions. There's also a link to this chapter:

http://msdn.microsoft.com/library/en-us/cpguide/html/cpcondatetimeformatstrings.asp


Armin
 
J

Jay B. Harlow [MVP - Outlook]

Rob,
In addition to the other comments:

| date....so it's truncating my fractions of a second!!!
Are you certain that it is truncating them as opposed to simply not showing
them?

See the remarks at:

http://msdn.microsoft.com/library/d.../cpref/html/frlrfsystemdatetimeclasstopic.asp

<quote>
DateTime values are measured in 100-nanosecond units called ticks, and a
particular date is the number of ticks since 12:00 midnight, January 1, 1,
A.D. (C.E.)
</quote>

100-nanosecond units should be more then enough to cover 1000th of a second!
Remember that a nanosecond is one billionth (10 to -9th) of a second.

DateTime values by default are only displayed to seconds, however this is
normally only a Display Issue! If you want the to see the 100-nanosecond
units, you need to use a custom DateTime format.

http://msdn.microsoft.com/library/d...ide/html/cpconcustomdatetimeformatstrings.asp

For example:

Dim aDate As DateTime = DirectCast(theDataView!theDateColumn,
DateTime)

Debug.WriteLine(aDate.ToString(), "default formatting")
Debug.WriteLine(aDate.ToString("yyyy.MM.dd hh:mm:ss.fffffff"),
"custom formatting")

The ".fffffff" says to display seconds fractions to the full seven digits
(100-nanoseconds), try the above two lines with the Date column in your
DataView. Try the above two lines with DateTime.Now

Dim aDate As DateTime = DateTime.Now

Debug.WriteLine(aDate.ToString(), "default formatting")
Debug.WriteLine(aDate.ToString("yyyy.MM.dd hh:mm:ss.fffffff"),
"custom formatting")

I suspect your fractions of seconds are not being truncated, rather they are
simply not being displayed!

Depending on how you are displaying the date you need to include a "format"
that includes fractions of seconds. For example with the Windows Forms
DataGrid, you can add a TableStyle for your table, then add a
DataGridTextBoxColumn for your date column. You can then set
DataGridTextBoxColumn.Format to a custom format that includes the fractions
of seconds you want displayed...


Hope this helps
Jay

| I'm storing a date/time into a SQL table of type datetime. I need it to
be
| precise so the value is stored to the 1000th of a second. ie "insert
into
| myTable mydate values ('08/05/2005 2:56:11.987'). This works fine...if
you
| check the value in the table with query analyzer, it shows in there
| properly.
|
| Now, in my app, I'm executing the same query (that I used in QA) and
storing
| tha in a dataview. If I break and watch the program, the value that's
| stored in the dataview is #8/5/2005 2:56:11 PM# with a datatype of
| date....so it's truncating my fractions of a second!!!
|
| How can I get my missing time? Thanks.
|
|
 
C

Cor Ligthert [MVP]

Rob,

Before this is misunderstood.
http://msdn.microsoft.com/library/d.../cpref/html/frlrfsystemdatetimeclasstopic.asp

<quote>
DateTime values are measured in 100-nanosecond units called ticks, and a
particular date is the number of ticks since 12:00 midnight, January 1, 1,
A.D. (C.E.)
</quote>

Be aware that this is for system.datetime. SQL server datetime is as I tried
to describe it.
I always forget that date therefore :)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_da-db_9xut.aspI hope this helps,Cor
 
J

Jay B. Harlow [MVP - Outlook]

Cor,
My point is that System.DateTime has create precision (uses smaller units)
then the DateTime on SQL Server.

Rob already mention that his SQL data had "1000th of a second" precision.

Hope this helps
Jay

| Rob,
|
| Before this is misunderstood.
| >
| >
http://msdn.microsoft.com/library/d.../cpref/html/frlrfsystemdatetimeclasstopic.asp
| >
| > <quote>
| > DateTime values are measured in 100-nanosecond units called ticks, and a
| > particular date is the number of ticks since 12:00 midnight, January 1,
1,
| > A.D. (C.E.)
| > </quote>
|
| Be aware that this is for system.datetime. SQL server datetime is as I
tried
| to describe it.
| I always forget that date therefore :)
|
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_da-db_9xut.aspI
hope this helps,Cor
|
 
C

Cor Ligthert [MVP]

Jay B. Harlow said:
Cor,
My point is that System.DateTime has create precision (uses smaller units)
then the DateTime on SQL Server.

Rob already mention that his SQL data had "1000th of a second" precision.

I saw that you showed it, I did not do any addition or comment to that.

However that the starting date of datetime is not always the same can be
confusing if you have first to handle with datetimes and therefore my
comment. It could have been seen by others than you or me that you made a
correction to my message about the start of the date in a SQL server.

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Doh!
| My point is that System.DateTime has create precision (uses smaller units)
| then the DateTime on SQL Server.
That's has *greater* precision.

Jay

| Cor,
| My point is that System.DateTime has create precision (uses smaller units)
| then the DateTime on SQL Server.
|
| Rob already mention that his SQL data had "1000th of a second" precision.
|
| Hope this helps
| Jay
|
| || Rob,
||
|| Before this is misunderstood.
|| >
|| >
|
http://msdn.microsoft.com/library/d.../cpref/html/frlrfsystemdatetimeclasstopic.asp
|| >
|| > <quote>
|| > DateTime values are measured in 100-nanosecond units called ticks, and
a
|| > particular date is the number of ticks since 12:00 midnight, January 1,
| 1,
|| > A.D. (C.E.)
|| > </quote>
||
|| Be aware that this is for system.datetime. SQL server datetime is as I
| tried
|| to describe it.
|| I always forget that date therefore :)
||
||
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_da-db_9xut.aspI
| hope this helps,Cor
||
|
|
 
H

Herfried K. Wagner [MVP]

Rob T said:
I assume you're referring to the fact that the datetime only goes to the
nearest second...or am I missing something?

No, I was referring to this paragraph:

| Time values are measured in 100-nanosecond units called ticks

You can determine the number of ticks by querying the 'Tick' property of
your 'DateTime' object.
 

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

Similar Threads

problem with date 6
Date time 4
Date/Time & Sql conversion issues 1
working with date types in a gridview 2
SQL Date comparison problem... 6
Taskcproblem calendar 4
Date Problem 1
SQL Date Problem 2

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top