M
matthias s.
Hi there,
I'm surely not the first one to have this problem. But searching the group
didn't yield any results, so here goes:
When storing DateTime values in an SQL Database (using a 'datetime' field),
the value returned by a subsequent query never exactly matches the DateTime
values inserted (I guess the DateTime struct has a different precision then
what is acutally saved to the DB), thus the following always fails:
DateTime dtNow = DateTime.Now;
// save dtNow to a SQL Database
....
// load it again into a variable called dtLoadedDateTime
....
if (dtLoadedDateTime == dtNow) {
// we never get here, cause the ticks are different
}
My question is, are there any utility classes which provide methods to
compare dates (up to a given precision)? I'm looking for methods like...
bool EqualToSecond(DateTime dtFirst, DateTime dtSecond){}
.... which should return true if the Dates equal up to a seconds precision. A
different number of ticks should be ignored (until there is so many of them
that the Seconds are affected).
If they don't exist, what would be the most effective way of writing them
(using the datetimes Hour, Minute, Second properties? using a TimeSpan?)
Any suggestions on this issue are very welcome. Thanks in advance!
/matthias
I'm surely not the first one to have this problem. But searching the group
didn't yield any results, so here goes:
When storing DateTime values in an SQL Database (using a 'datetime' field),
the value returned by a subsequent query never exactly matches the DateTime
values inserted (I guess the DateTime struct has a different precision then
what is acutally saved to the DB), thus the following always fails:
DateTime dtNow = DateTime.Now;
// save dtNow to a SQL Database
....
// load it again into a variable called dtLoadedDateTime
....
if (dtLoadedDateTime == dtNow) {
// we never get here, cause the ticks are different
}
My question is, are there any utility classes which provide methods to
compare dates (up to a given precision)? I'm looking for methods like...
bool EqualToSecond(DateTime dtFirst, DateTime dtSecond){}
.... which should return true if the Dates equal up to a seconds precision. A
different number of ticks should be ignored (until there is so many of them
that the Seconds are affected).
If they don't exist, what would be the most effective way of writing them
(using the datetimes Hour, Minute, Second properties? using a TimeSpan?)
Any suggestions on this issue are very welcome. Thanks in advance!
/matthias