Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

date calculation inside select clause

 
rick collette
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have two columns of type TIMESTAMP defined inside a table:
start_date and stop_date. Is there any way I can calculate
how many days between start_date and stop_date inside my SELECT
clause so that I do not have do it after I get these two values
from my database?

regards,
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rick,
In db2, there is a days() function. So you could easily subtract in your select clause. I don't remember if this is db2 specific though.
 
arnel nicolas
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also in MSSQL you can use DATEDIFF function.
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Oracle, AFAIK, you can just subtract one date from the other to get the number of days
 
rick collette
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot guys. I am using db2. I will try out you guys' suggestions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic