Answers.Body: <p>I'd use <code>System.get</code> API call. (<a href="https://github.com/civicrm/civicrm-core/blob/master/api/v3/System.php#L222">source</a>)</p>
  
  <p>In the return values, there's a value for <code>version</code> which corresponds to the value in <code>civicrm-version.php</code></p>
  
  <pre><code>$ cv api System.get name=version
  {
      "is_error": 0,
      "version": 3,
      "count": 1,
      "id": 0,
      "values": [
          {
              "version": "4.6.20.0",
              "uf": "Drupal",
              "php": {
              // lots more info ...
  </code></pre>
  
  <p>Only worry about this might be how heavy that API call is - since I see data there from OS etc, it might not be suitable for calling frequently if rebuilding the data each time. There seems to be a bit of overhead to this API call (~0.07s per call in a randomly picked test environment), so for frequent use you'd want something lighter.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-18T03:30:33.093Z
Answers.LastActivityDate: 2017-01-18T03:51:25.787Z
Answers.LastEditDate: 2017-01-18T03:51:25.787Z
Answers.UserDisplayName: Chris Burgess
Answers.Body: <p>Agree with Chris that <code>System.get</code> is a great API for inspecting the system -- with a trade-off of breadth vs speed.</p>
  
  <p>If you need something more performant, use <code>CRM_Utils_System::version()</code>, e.g.</p>
  
  <pre><code>$ cv ev 'return CRM_Utils_System::version();'
  "4.7.16"
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-18T04:35:51.583Z
Answers.LastActivityDate: 2017-01-18T04:35:51.583Z
Answers.UserDisplayName: Tim Otten
Body: <p>Within a CiviCRM extension, what's the best way to determine the current CiviCRM version in versions 4.6.x and above?</p>
  
Tags: <extension><developer>
Title: Find CiviCRM version programmatically?
ThreadText: # Find CiviCRM version programmatically?
  
  (Asked by: username_0 on 2017-01-18)
  
  Within a CiviCRM extension, what's the best way to determine the current CiviCRM version in versions 4.6.x and above?
  
  **Tags:** extension, developer
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-01-18. Score: 8 | Accepted answer
  
  Agree with Chris that System.get is a great API for inspecting the system -- with a trade-off of breadth vs speed.
  If you need something more performant, use CRM_Utils_System::version(), e.g.
  $ cv ev 'return CRM_Utils_System::version();'
  "4.7.16"
  
  
  ---
  
  ### Answer by username_1 on 2017-01-18. Score: 7
  
  I'd use System.get API call. (source)
  In the return values, there's a value for version which corresponds to the value in civicrm-version.php
  $ cv api System.get name=version
  {
      "is_error": 0,
      "version": 3,
      "count": 1,
      "id": 0,
      "values": [
          {
              "version": "4.6.20.0",
              "uf": "Drupal",
              "php": {
              // lots more info ...
  
  Only worry about this might be how heavy that API call is - since I see data there from OS etc, it might not be suitable for calling frequently if rebuilding the data each time. There seems to be a bit of overhead to this API call (~0.07s per call in a randomly picked test environment), so for frequent use you'd want something lighter.
  
  
  ---
  
  