time comarison querry

Posted by Veeresh under Sql Server on 4/20/2009 | Views : 1064 | Status : [Member] | Replies : 1
hi

please any one help me to solve my issue.
i have two colums of datetime type and i want get difference of two datatime fields and then select the rows lesser then 30 min\
example:

table1
name(char) stdat(datetype) cldate(datetype)




select name whose difference stdat and cldate lesser then 30 minutes




Responses

Posted by: Vuyiswamb on: 4/22/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Afternoon Veeresh

Welcome to Dotnetfunda

Here is your Answer, i have done it using my Example and you can take it from there. i first Created a Table

CREATE TABLE DATE_CHECK

(

DATE_START DATETIME NULL,
DATE_END DATETIME NULL)


and inserted some dummy data like this

INSERT INTO DATE_CHECK
VALUES('2002/04/01','2003/04/01')


and checked the Difference like this

SELECT DATEDIFF(MI,DATE_START,DATE_END)

FROM DATE_CHECK
WHERE DATE_START < 30 AND DATE_END < 30


The "MI" stands for the Minute

Thank you for posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Veeresh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response