Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Dates and Dividing/Rounding

Status
Not open for further replies.

pcawdron

Programmer
Jun 14, 2000
109
0
0
AU
Hi,<br><br>I'm working on an AS400 DB2.&nbsp;&nbsp;I have two dates, START_DATE and CURDATE().&nbsp;&nbsp;I need to know how many months there are between these two dates.&nbsp;&nbsp;Currently I'm using (CURDATE()-START_DATE)/30.&nbsp;&nbsp;But this slows the query down and leaves me with a DECIMAL running out to 0.0000000000.&nbsp;&nbsp;Is there a better way of accomplishing this?&nbsp;&nbsp;How can I round the result?<br><br>i.e 4.23 becomes 4 months while 5.51 becomes 6 months<br><br>Thanks for your help with this<br><br>&nbsp;
 
Try this:<br><br>select round((Curdate-Start_date)/30) from TableName<br>where rownum&lt;=2
 
ROUND is not an AS400 DB2 SQL function so that didn't work.
 
HI, is there a MOD operator (or something like this, returning the integer part of a DIVISION operation) in AS400 DB2 SQL? If it is, you can use an expresion like:<br>MOD((CURDATE-START_DATE),30). In other language there's an operator for MOD operation, the '%' symbol. You can use like this: (CURDATE-START_DATE)%30.<br>I hope this helps you.<br>Regards, <p>Eduard Stoleru<br><a href=mailto:e_stoleru@yahoo.com>e_stoleru@yahoo.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top