All Forums Database
Alex181 11 posts Joined 08/14
08 Sep 2014
Days between two dates (different years)

Hello, 
cast(cast(cast(min(sale_date)as date format 'yyyy-mm-dd') as char(10)) - '2013- 11-01' as decimal(15,0)) as sale_days
the above query is working only for dates_ between in 2013. Can somebody help me fix this query to work for days between 2014 and 2013?
 
Thanks

Priya01 10 posts Joined 08/14
08 Sep 2014

Try this..
cast(cast(min(sale_date)as date format 'yyyy-mm-dd') - cast('2013- 11-01' as date format 'yyyy-mm-dd') as decimal(15,0)) as sale_days

Raja_KT 1246 posts Joined 07/09
08 Sep 2014

Your dates are in different formats:
Try to  bring both in the same  format  say example below:
SELECT DATE '2014- 11-01' - DATE '2013- 11-01';
 

Raja K Thaw
My wiki: http://en.wikipedia.org/wiki/User:Kt_raj1
Street Children suffer not by their fault. We can help them if we want.

Alex181 11 posts Joined 08/14
08 Sep 2014

 I cannot enter the date directly, I need to get that from minimum of sales_date. how can I format this date?
cast(cast(cast(min(sale_date)as date format 'yyyy-mm-dd') as char(10))

Raja_KT 1246 posts Joined 07/09
08 Sep 2014

What values you get from cast(cast(min(sale_date)as date format 'yyyy-mm-dd')) ?
Do a select of your cast date and see its value.
So you can think of bringing to the same format like :
SELECT cast(min(sale_date)as date format 'yyyy-mm-dd')) - DATE '2013- 11-01';
 
 

Raja K Thaw
My wiki: http://en.wikipedia.org/wiki/User:Kt_raj1
Street Children suffer not by their fault. We can help them if we want.

Alex181 11 posts Joined 08/14
08 Sep 2014

That worked, Thank you.

You must sign in to leave a comment.