| Author |
Topic |
|
jamie_pattison
Yak Posting Veteran
65 Posts |
Posted - 2008-08-14 : 09:53:43
|
| I have some SQL codeCONVERT(VARCHAR(10), ReportDate,105).....DATEDIFF (day, ReportDate,DD-MM-YYYY)Im trying to find the difference between ReportDate and todays date (DD-MM-YYYY) but no joy.How may this be accomplished?Thank you |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-14 : 09:57:57
|
| SELECT DATEDIFF(day,ReportDate,GETDATE()) from tableMadhivananFailing to plan is Planning to fail |
 |
|
|
jamie_pattison
Yak Posting Veteran
65 Posts |
Posted - 2008-08-14 : 10:05:41
|
| I receive a syntax error - Why do you have From Table?The date should be todays date and not pulled from any table?Thanks |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-08-14 : 10:07:27
|
| where are you getting ReportDate from if not a table?Em |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-14 : 10:10:26
|
quote: Originally posted by jamie_pattison I receive a syntax error - Why do you have From Table?The date should be todays date and not pulled from any table?Thanks
What is the error?Is ReportDate a column of a table?MadhivananFailing to plan is Planning to fail |
 |
|
|
jamie_pattison
Yak Posting Veteran
65 Posts |
Posted - 2008-08-14 : 10:11:54
|
| ReportDate is a field in a "table". So im trying to figure out what the difference is between the date from ReportDate and todays date.....Error is Incorrect syntax near DateDiff. |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-08-14 : 10:13:31
|
| then what's wrong with the query? you do know that "From Table" means from YOUR table (whatever it's called)?Em |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-14 : 10:15:40
|
quote: Originally posted by jamie_pattison ReportDate is a field in a "table". So im trying to figure out what the difference is between the date from ReportDate and todays date.....Error is Incorrect syntax near DateDiff.
Can you post the full code you used?MadhivananFailing to plan is Planning to fail |
 |
|
|
jamie_pattison
Yak Posting Veteran
65 Posts |
Posted - 2008-08-14 : 10:23:23
|
| I gathered it means from "my table" but i thought i could just type in the dateDiff function to get the results and use From later on in the query.My code isSELECTCONVERT(VARCHAR(10), TBL.[ReportDate],105) As ReportDate,CONVERT(VARCHAR(10), TBL.[User],105) As UserDate,DATEDIFF (day, TBL.[ReportDate], GETDATE()) FROM Database.Internal.ProceduresFirst guess is that its having problems converting the date 105 (formatted in dd-mm-yyyy) to GETDATE which i think is mm-dd-yyyy 00:00:00.000Thanks |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-08-14 : 10:26:42
|
| why the TBL prefix? how is reportdate stored in the database? is it a datetime?Em |
 |
|
|
jamie_pattison
Yak Posting Veteran
65 Posts |
Posted - 2008-08-14 : 10:46:50
|
| TBL was a typo and yes its a datetime..... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-14 : 10:51:18
|
| Do you get any errors?SELECT[ReportDate] As ReportDate,[User] As UserDate,DATEDIFF (day, [ReportDate], GETDATE()) FROMDatabase.Internal.ProceduresMadhivananFailing to plan is Planning to fail |
 |
|
|
|