13,089,943 members (48,240 online)
Rate this:
See more:
In SQL SERVER 2005/2008 I am trying to retrieve a certain range of dates. I tried to convert the DateTime datatype to a numeric and a decimal using CONVERT, but this did not work. It gave me a ficticous number. How would you manipulate the DateTime datatype to focus in on a desired range of dates using T-SQL????
Posted 26-Jul-11 4:52am
SQL Ed359
_Zorro_ 26-Jul-11 10:54am

I probably am missing something, but why would you want to convert a DateTime to Decimal ?!
SQL Ed 26-Jul-11 12:00pm

The question clearly states more than one time that I am trying to retrieve a desired range of dates.

Rate this:

Rate this:

## Solution 2

Why convert it at all? If you have a DateTime, use it as a DateTime!
`SELECT * FROM myTable WHERE dateEntered < '2011-05-01'`
Rate this:

## Solution 3

Hi,

When ever checking date time column, U need to convert "112" format. check the following example.

```
DECLARE @DateTime TABLE(ID INT IDENTITY(1,1),EmpName VARCHAR(100),DOJ DATETIME )
DECLARE @FDate DATETIME,@TDate DATETIME

INSERT INTO @DateTime(EmpName,DOJ)
SELECT 'Kumar',GETDATE()
UNION ALL
SELECT 'Raja',GETDATE()-10
UNION ALL
SELECT 'Sive',GETDATE()-50
UNION ALL
SELECT 'Venkat',GETDATE()-100

SELECT @FDate=GETDATE()-30,@TDate=GETDATE()
SELECT @FDate,@TDate
SELECT * FROM @DateTime
WHERE CONVERT(VARCHAR(10),DOJ,112) BETWEEN CONVERT(VARCHAR(10),@FDate,112) AND CONVERT(VARCHAR(10),@TDate,112)
```

In this example the DateTime Column values like "2012-01-23 18:32:59.960" is Converted to "20120123" (We will do this as Number or Varchar).
this format 112 is gives you as 2012 year , 01 month, 23 day (20120123).

With Regards,
GVPrabu

Top Experts
Last 24hrsThis month
 ProgramFOX 250 Richard Deeming 220 Graeme_Grant 150 OriginalGriff 150 ppolymorphe 120
 OriginalGriff 3,412 Graeme_Grant 1,874 ProgramFOX 1,707 Jochen Arndt 1,645 ppolymorphe 1,507