Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to get the difference of two dates?

Author  Topic 

jonasdavedomingo
Starting Member

33 Posts

Posted - 2004-10-20 : 23:19:49
let's say i have a table named tblData and has 4 columns: data_RefNo, data_DateReported, data_TargetDate, data_Data

tblData returns 2 rows.

data_RefNo.............data_DateReported.............data_TargetDate........................data_Data
10000................10-20-2004 10:55:44 AM........10-20-2004 10:57:44 AM........Slow Response Time
10000................10-21-2004 10:55:44 AM........10-21-2004 11:55:44 AM........Bug Error

i just wana ask how to get the difference of the date_DateReported and date_TargetDate.

_______________

i tried this code but it didnot work


public Vector get_con_pf()
{
Vector vData = new Vector();
String query = "SELECT * FROM tblData WHERE data_RefNo= '"'10000'"'";

try
{
DBConnect db = new DBConnect();
db.openCon();
ResultSet rs = db.execute(query);

while (rs.next())
{
vData.addElement(DATEDIFF(mi, rs.getString("st_DateReported"), rs.getString("st_TargetFinishDate")));
}

db.closeCon();
}
catch (Exception e)
{
System.out.println("Error: " + e );
}

return vData;
}


_____________________

i want to return the difference of the data_DateReported and date_TargetDate, i did this
vData.addElement(DATEDIFF(mi, rs.getString("st_DateReported"), rs.getString("st_TargetFinishDate")));

but it didnot work.

How do i get that? because i want to return a vector.

_____________________

the code must return the values:
2 for the 1st rows because the difference is only 2 minutes, and
60 for the 2nd row.

jonasdavedomingo
Starting Member

33 Posts

Posted - 2004-10-20 : 23:29:31
ooops i tried this one:


query = "SELECT *, DATEDIFF(mi, data_DateReported, data_TargetDate) AS diff FROM tblData WHERE data_RefNo = '10000'";


and it works.
hehehehe!!!!!!

problem solved! :)
Go to Top of Page
   

- Advertisement -