Have a Question?

If you have any question you can ask below or enter what you are looking for!



sql server qestion

while running  the below query :
       
        select books,[date of purchase],[date of submit],
         convert(nvarchar(10),[DATE of Purchase],103),
         convert (nvarchar(10),[DATE of submit],103),
         datediff(day,[date of Purchase],[date of submit])[ days count]from libencore

got the below result :

books    date of purchase    date of submit    (No column name)    (No column name)     days count
A       2016-01-06 00:00:00.000    06-20-2016    06/01/2016    06-20-2016                     166
B       2016-02-06 00:00:00.000    06-21-2016    06/02/2016    06-21-2016                     136
C      2016-03-06 00:00:00.000    06-22-2016    06/03/2016    06-22-2016                      108
D      2016-04-06 00:00:00.000    06-23-2016    06/04/2016    06-23-2016                       78
E     2016-05-06 00:00:00.000    06-24-2016    06/05/2016    06-24-2016                       49
F     2016-06-06 00:00:00.000    06-25-2016    06/06/2016    06-25-2016                       19

now looking for result difference of two no of columns . in days column must be :

(6-21-206 - 06/02/2016) = 19 days in day column and so on .










  dev

I check your question and found that the formatting of date both (date of purchase and date of submit) are not similar that's the reason you are getting this error.

I used similar date formatting for both the dates and found appropriate result. see the query below-

select datediff(dd,'06-02-2016','06-21-2016') the result is 19 which is appropriate.

Thanks,


  Devbrat Tripathi       27 Jun 2016       0       0     

Post Your Answers:

Please use the CODE HIGHLIGHT Button to format/highlight your codes if any