Question Locked

Tech Question : Date Math

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I get the following result in a third party tool (correct):
Rqst No. Duration
1 82414 7.0001504629629629629629629629629629629
2 82415 14.000254629629629629629629629629629629

? and this using Visual Studio (wrong)
Rqst No. Duration
1 82414 -90
2 82415 0

?using
SELECT a.rqst_num, ROUND(b.rec_create_tms - a.rec_create_tms) as duration
FROM log a, log b
WHERE a.rqst_num = b.rqst_num
AND a.log_ty_num = 6
AND b.log_ty_num = 9
AND a.rqst_num IN (82415,82414)

Code Snippet:
try
{
string sqlStatement = string.Format(
@"SELECT a.rqst_num,
(b.rec_create_tms - a.rec_create_tms) as duration
FROM log a, log b
WHERE a.rqst_num = b.rqst_num
AND a.log_ty_num = {0}
AND b.log_ty_num = {1}
AND a.rqst_num IN ({2})", logTy1, logTy2, rqstStr);
IDataReader dataReader2 = DAOHelper.ExecuteSQLStatement(sqlStatement);
while (dataReader2.Read())
{
int rqstNum = dataReader2.GetInt32(0);
int duration = dataReader2.GetInt32(1);

Rqst rqst = new Rqst(rqstNum);
rqst = rqst.GetRqst();
rqst.GenericValue = duration;

rqstList.Add(rqst);
}
dataReader2 = null;
}
catch (Exception exception)
{
throw new Exception("Common.DAO: ReportDAO: GetAuditReportDetails()", exception.InnerException);
}

Any ideas?

3 replies

by cmiller5400

Use a Double data type instead of a Int32. It is more precise.

by tony hopkinson

dayssincebasedate.secondssincemidnight

Personally I'd be making use of the function DateDiff in SQL, or if in .net the TimeSpan class.

This discussion is closed to new replies.