hi guyz i want to compare time from DateTime field i.e. i want to identify if the time is from 1pm to 2pm the do this else do.....
select DATEPART(hour, loginTime) .....returns me the hour i can get the Hour part of the time but the prblem is how to identify it
whether it is less than 2:00:00 pm and greater than 1:00:00 pm i can do this task using at application level but i want this to b done at query level
any ideas????
i used following query..
my table is like Finddate
id bdate
1 2007-01-01 13:30:00.000
2 2007-01-01 14:30:00.000
3 2007-01-01 14:20:00.000
4 2007-01-01 23:30:00.000
5 2007-01-01 22:30:00.000
and i am selecting the records between 1 to 2 pm.
1 pm means 13 and 2 pm means 14, so i written query
select*from finddatewheredatepart(hour,bdate)>=13anddatepart(hour,bdate)<=14
this will gives me result as
id bdate
1 2007-01-01 13:30:00.000
2 2007-01-01 14:30:00.000
3 2007-01-01 14:20:00.000
hope this will help u..
|||
hi Mahadeomatre thnx for ur help i got the solution,ur query should b like this.
select*from finddatewheredatepart(hour,bdate) >=13anddatepart(hour,bdate)<14
then according to ur table it wil return only 1st row
1 2007-01-01 13:30:00.000
and "datepart(hour,bdate)<14" will omit the other two rows as per requirment.
2 2007-01-01 14:30:00.000
3 2007-01-01 14:20:00.000
No comments:
Post a Comment