Skip to main content

Convert between Localdate to sql Date in Java [2021]

Convert between Localdate to SQL Date in Java [2021] 

In this tutorial, we will see Java 8 examples to convert from java.time.LocalDate to SQL Date and vice versa.

LocalDate to Sql Date

java.time.LocalDate to java.sql.Date

To Get java.sql.Date from LocalDate we will use java.sql.Date.valueOf(LocalDate localDate) method. 


 import java.time.LocalDate;

 //LocalDate to sql Date
 public class LocalDateToSqlDateEx {
  public static void main(String[] args) {
    // LocalDate instance
    LocalDate localDate = LocalDate.now();
    System.out.println("LocalDate : " + localDate);

    // Get sql Date from LocalDate instance
    java.sql.Date sqlDate = java.sql.Date.valueOf(localDate);
    System.out.println("LocalDate to sql Date : " + sqlDate);


LocalDate : 2020-07-17
LocalDate to sql Date : 2020-07-17

Sql Date to LocalDate

java.sql.Date to java.time.LocalDate

To get LocalDate from java.sql.Date we use java.sql.Date.toLocalDate() method.


 import java.time.LocalDate;
 import java.util.Date;

 //Sql Date to LocalDate
 public class SqlDateToLocalDate {
   public static void main(String[] args) {
     // java.sql.Date instance
     java.sql.Date sqlDate = new java.sql.Date(new Date().getTime());
     System.out.println("SqlDate : " + sqlDate);

     // Get LocalDate from SQL date
     LocalDate localDate = sqlDate.toLocalDate();
     System.out.println("Sql Date to LocalDate : " + localDate);


SqlDate : 2020-07-17
Sql Date to LocalDate : 2020-07-17


In this quick tutorial, we have covered how to convert localdate to SQL date and how to convert SQL data to LocalDate using Java 8.

Thanks for reading this tutorial so far. If you like this tutorial then please share it with your friends and colleagues. If you have any questions, doubts, suggestions, or feedback then please drop a comment and I'll try to answer your question.

Happy Learning!!!

More Examples you may like