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
 General SQL Server Forums
 New to SQL Server Programming
 Query Help Datetime datatype

Author  Topic 

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2012-01-31 : 02:37:11

Hi Expert

I have a field with datetime datatype.
i just want to validate and pullout data using the date and time.
something like this.. from '2012-01-29' and 12:00AM to '2012-01-30' and 12:00AM


Sample table

Create Table #TABLE1
(ASURAFDATETIME datetime)

Insert into #TABLE1 values ('2012-01-30 00:54:05.000')
Insert into #TABLE1 values ('2012-01-30 11:52:48.000')
Insert into #TABLE1 values ('2012-01-30 00:55:15.000')
Insert into #TABLE1 values ('2012-01-29 19:30:54.000')
Insert into #TABLE1 values ('2012-01-30 00:55:38.000')
Insert into #TABLE1 values ('2012-01-30 04:39:50.000')

Select * #Table1
where ASURAFDATETIME >='2012-01-29' and ASURAFDATETIME < '2012-01-31'
and ???
[code]
[\code]

Thanks,

JOV

sql-programmers
Posting Yak Master

190 Posts

Posted - 2012-01-31 : 04:12:22

select * from #TABLE1 where ASURAFDATETIME > CONVERT(datetime, '2012-01-29') AND
ASURAFDATETIME < CONVERT(datetime, '2012-01-29')

If you want to add time then

select * from #TABLE1 where ASURAFDATETIME > CONVERT(datetime, '2012-01-29 12:35AM') AND
ASURAFDATETIME < CONVERT(datetime, '2012-01-29 12:35AM')

SQL Server Programmers and Consultants
http://www.sql-programmers.com/
Go to Top of Page

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2012-01-31 : 04:28:17
Thank you very much..
Go to Top of Page
   

- Advertisement -