How to compare 2 java.sql.Date in scala?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have some date in format java.sql.Date and I want to compare them



import java.sql.Date
import org.apache.spark.sql.types.{DateType, IntegerType}
var a = Date.valueOf("2018-11-09")
var b = Date.valueOf("2019-11-09")

a: java.sql.Date = 2018-11-09
b: java.sql.Date = 2019-11-09


If I compare with an equal sign it work



a == b
res1: Boolean = false


But if I want to know wich one is buigger than the other it return an error:



 a >= b
<console>:37: error: value > is not a member of java.sql.Date


I would expect it to return false ...



How can I compare a and b...?










share|improve this question





























    0















    I have some date in format java.sql.Date and I want to compare them



    import java.sql.Date
    import org.apache.spark.sql.types.{DateType, IntegerType}
    var a = Date.valueOf("2018-11-09")
    var b = Date.valueOf("2019-11-09")

    a: java.sql.Date = 2018-11-09
    b: java.sql.Date = 2019-11-09


    If I compare with an equal sign it work



    a == b
    res1: Boolean = false


    But if I want to know wich one is buigger than the other it return an error:



     a >= b
    <console>:37: error: value > is not a member of java.sql.Date


    I would expect it to return false ...



    How can I compare a and b...?










    share|improve this question

























      0












      0








      0


      1






      I have some date in format java.sql.Date and I want to compare them



      import java.sql.Date
      import org.apache.spark.sql.types.{DateType, IntegerType}
      var a = Date.valueOf("2018-11-09")
      var b = Date.valueOf("2019-11-09")

      a: java.sql.Date = 2018-11-09
      b: java.sql.Date = 2019-11-09


      If I compare with an equal sign it work



      a == b
      res1: Boolean = false


      But if I want to know wich one is buigger than the other it return an error:



       a >= b
      <console>:37: error: value > is not a member of java.sql.Date


      I would expect it to return false ...



      How can I compare a and b...?










      share|improve this question














      I have some date in format java.sql.Date and I want to compare them



      import java.sql.Date
      import org.apache.spark.sql.types.{DateType, IntegerType}
      var a = Date.valueOf("2018-11-09")
      var b = Date.valueOf("2019-11-09")

      a: java.sql.Date = 2018-11-09
      b: java.sql.Date = 2019-11-09


      If I compare with an equal sign it work



      a == b
      res1: Boolean = false


      But if I want to know wich one is buigger than the other it return an error:



       a >= b
      <console>:37: error: value > is not a member of java.sql.Date


      I would expect it to return false ...



      How can I compare a and b...?







      scala date apache-spark






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 13:38









      AnnesoAnneso

      749




      749
























          2 Answers
          2






          active

          oldest

          votes


















          3














          You may use java.sql.Date#compareTo:



          var a = Date.valueOf("2018-11-09")
          var b = Date.valueOf("2019-11-09")

          if (b.compareTo(a) > 0) {
          println("Date b is later than date a.");
          }





          share|improve this answer
























          • Thank you !!! :-)

            – Anneso
            Nov 16 '18 at 15:26



















          2














          If you want to use the comparison operators such as a >= b instead of compareTo, you can: just add



          import scala.math.Ordering.Implicits._


          for Comparable types. java.sql.Date is actually a bit unusual, because it's Comparable with java.util.Date and not java.sql.Date. So for this type you need type ascription:



          (a: java.util.Date) >= b





          share|improve this answer


























          • OK, edited (I started writing my answer before yours appeared).

            – Alexey Romanov
            Nov 16 '18 at 13:49











          • Hi Alexey Romanov, thank you for your answer however it does not work with me..... I do the import "import scala.math.Ordering.Implicits._" but when I tried a>= b I still get the same error...

            – Anneso
            Nov 16 '18 at 15:27











          • @Anneso Edited it.

            – Alexey Romanov
            Nov 16 '18 at 17:22












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338980%2fhow-to-compare-2-java-sql-date-in-scala%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          You may use java.sql.Date#compareTo:



          var a = Date.valueOf("2018-11-09")
          var b = Date.valueOf("2019-11-09")

          if (b.compareTo(a) > 0) {
          println("Date b is later than date a.");
          }





          share|improve this answer
























          • Thank you !!! :-)

            – Anneso
            Nov 16 '18 at 15:26
















          3














          You may use java.sql.Date#compareTo:



          var a = Date.valueOf("2018-11-09")
          var b = Date.valueOf("2019-11-09")

          if (b.compareTo(a) > 0) {
          println("Date b is later than date a.");
          }





          share|improve this answer
























          • Thank you !!! :-)

            – Anneso
            Nov 16 '18 at 15:26














          3












          3








          3







          You may use java.sql.Date#compareTo:



          var a = Date.valueOf("2018-11-09")
          var b = Date.valueOf("2019-11-09")

          if (b.compareTo(a) > 0) {
          println("Date b is later than date a.");
          }





          share|improve this answer













          You may use java.sql.Date#compareTo:



          var a = Date.valueOf("2018-11-09")
          var b = Date.valueOf("2019-11-09")

          if (b.compareTo(a) > 0) {
          println("Date b is later than date a.");
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 13:43









          Tim BiegeleisenTim Biegeleisen

          237k13100160




          237k13100160













          • Thank you !!! :-)

            – Anneso
            Nov 16 '18 at 15:26



















          • Thank you !!! :-)

            – Anneso
            Nov 16 '18 at 15:26

















          Thank you !!! :-)

          – Anneso
          Nov 16 '18 at 15:26





          Thank you !!! :-)

          – Anneso
          Nov 16 '18 at 15:26













          2














          If you want to use the comparison operators such as a >= b instead of compareTo, you can: just add



          import scala.math.Ordering.Implicits._


          for Comparable types. java.sql.Date is actually a bit unusual, because it's Comparable with java.util.Date and not java.sql.Date. So for this type you need type ascription:



          (a: java.util.Date) >= b





          share|improve this answer


























          • OK, edited (I started writing my answer before yours appeared).

            – Alexey Romanov
            Nov 16 '18 at 13:49











          • Hi Alexey Romanov, thank you for your answer however it does not work with me..... I do the import "import scala.math.Ordering.Implicits._" but when I tried a>= b I still get the same error...

            – Anneso
            Nov 16 '18 at 15:27











          • @Anneso Edited it.

            – Alexey Romanov
            Nov 16 '18 at 17:22
















          2














          If you want to use the comparison operators such as a >= b instead of compareTo, you can: just add



          import scala.math.Ordering.Implicits._


          for Comparable types. java.sql.Date is actually a bit unusual, because it's Comparable with java.util.Date and not java.sql.Date. So for this type you need type ascription:



          (a: java.util.Date) >= b





          share|improve this answer


























          • OK, edited (I started writing my answer before yours appeared).

            – Alexey Romanov
            Nov 16 '18 at 13:49











          • Hi Alexey Romanov, thank you for your answer however it does not work with me..... I do the import "import scala.math.Ordering.Implicits._" but when I tried a>= b I still get the same error...

            – Anneso
            Nov 16 '18 at 15:27











          • @Anneso Edited it.

            – Alexey Romanov
            Nov 16 '18 at 17:22














          2












          2








          2







          If you want to use the comparison operators such as a >= b instead of compareTo, you can: just add



          import scala.math.Ordering.Implicits._


          for Comparable types. java.sql.Date is actually a bit unusual, because it's Comparable with java.util.Date and not java.sql.Date. So for this type you need type ascription:



          (a: java.util.Date) >= b





          share|improve this answer















          If you want to use the comparison operators such as a >= b instead of compareTo, you can: just add



          import scala.math.Ordering.Implicits._


          for Comparable types. java.sql.Date is actually a bit unusual, because it's Comparable with java.util.Date and not java.sql.Date. So for this type you need type ascription:



          (a: java.util.Date) >= b






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 16 '18 at 17:20

























          answered Nov 16 '18 at 13:45









          Alexey RomanovAlexey Romanov

          111k26215358




          111k26215358













          • OK, edited (I started writing my answer before yours appeared).

            – Alexey Romanov
            Nov 16 '18 at 13:49











          • Hi Alexey Romanov, thank you for your answer however it does not work with me..... I do the import "import scala.math.Ordering.Implicits._" but when I tried a>= b I still get the same error...

            – Anneso
            Nov 16 '18 at 15:27











          • @Anneso Edited it.

            – Alexey Romanov
            Nov 16 '18 at 17:22



















          • OK, edited (I started writing my answer before yours appeared).

            – Alexey Romanov
            Nov 16 '18 at 13:49











          • Hi Alexey Romanov, thank you for your answer however it does not work with me..... I do the import "import scala.math.Ordering.Implicits._" but when I tried a>= b I still get the same error...

            – Anneso
            Nov 16 '18 at 15:27











          • @Anneso Edited it.

            – Alexey Romanov
            Nov 16 '18 at 17:22

















          OK, edited (I started writing my answer before yours appeared).

          – Alexey Romanov
          Nov 16 '18 at 13:49





          OK, edited (I started writing my answer before yours appeared).

          – Alexey Romanov
          Nov 16 '18 at 13:49













          Hi Alexey Romanov, thank you for your answer however it does not work with me..... I do the import "import scala.math.Ordering.Implicits._" but when I tried a>= b I still get the same error...

          – Anneso
          Nov 16 '18 at 15:27





          Hi Alexey Romanov, thank you for your answer however it does not work with me..... I do the import "import scala.math.Ordering.Implicits._" but when I tried a>= b I still get the same error...

          – Anneso
          Nov 16 '18 at 15:27













          @Anneso Edited it.

          – Alexey Romanov
          Nov 16 '18 at 17:22





          @Anneso Edited it.

          – Alexey Romanov
          Nov 16 '18 at 17:22


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338980%2fhow-to-compare-2-java-sql-date-in-scala%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          List item for chat from Array inside array React Native

          Thiostrepton

          Caerphilly