-
How to find 'x' number of days from 'yyyymmdd' format?
I need to find out the count of number of records older than 100 days from a table having 'order_date' as yyyymmdd format eg. 20041115. Thanks in advance.
-
select datediff(dd,'20031111','20041201')
-
select datediff(dd,'20031111','20041201')
select datediff(dd,'2003/11/11','2004/12/01')
select datediff(dd,'2003-11-11 12:00:00','2004-12-01 19:25:00')
select datediff(dd,'2003-11-11 23:00:00','2004-12-01 19:25:00')
-
I will not be knowing the dates so as to hard code them in the query..instead I need to find out how many records are there which are older than say 100days from a table like this:
order_number order_date
1001 20041023
1002 20041023
10003 20041023
7687 20041023
7909 20041023
7699 20041023
9878 20041023
Any help?
-
Select Count(*)
From myTable
Where DateDiff(dd, order_date, getdate()) > 100
-
I am getting this error as order_date is declared as int for some reason:
Server: Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type datetime.
-
Set DateFormat ymd
Select Count(*)
From myTable
Where DateDiff(dd, Cast(order_date as varchar)), getdate()) > 100
-
Getting the following error again:
Server: Msg 174, Level 15, State 1, Line 3
The datediff function requires 3 arguments.
-
Sorry, had a typo in my code:
Select Count(*)
From myTable
Where DateDiff(dd, Cast(order_date as varchar), getdate()) > 100
-
It worked! Thank you Rawhide and everyone :-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|