How to convert java.sql.Timestamp to LocalDate (Java 8 java.time)
Codemia Knowledge Hub ·
Use timestamp.toLocalDateTime().toLocalDate() if you just want the date part of the stored local timestamp. Use timestamp.toInstant().atZone(zoneId).toLocalDate() if the timestamp is a moment in time and you want the date in a particular zone. The two can give different dates, so pick the one that matches what the value means.
Drop the time with toLocalDateTime()
If the Timestamp represents a local database timestamp and you want its date portion, go through toLocalDateTime():
This is usually the cleanest choice when you map a SQL TIMESTAMP column into local date logic without any time-zone conversion.
Go through Instant when the zone matters
If the timestamp is a moment on the timeline, convert it to Instant, apply a ZoneId, and take the LocalDate:
The zone matters because the same instant can fall on different calendar dates in different regions.
Which conversion to use
toLocalDateTime().toLocalDate()when you want the local date portion of the stored value.toInstant().atZone(...).toLocalDate()when the timestamp is a real moment in time in a specific zone.
They are not always interchangeable. Near midnight, changing the zone can move the date backward or forward.
Reading the value from JDBC
The question often comes up when reading from a ResultSet:
That is convenient, but decide whether local timestamp semantics are right for that column. Some systems store UTC-oriented timestamps and expect application code to interpret them in a specific zone. Others treat the value as a plain local timestamp with no time-zone meaning. The right conversion depends on what the schema means, not on what compiles.
Handling null columns
For a nullable column, check for null before converting:
If null is not a valid domain value, turn it into an optional or a validation error early instead of letting it travel through the application.
Also ask whether the column should be a timestamp at all. If the business concept is date-only, a SQL DATE may give clearer code than converting a timestamp and discarding information.
Write tests around midnight boundaries. That is where the zone-sensitive path and the local timestamp path are most likely to diverge visibly.
Mistakes to avoid
- Treating every timestamp-to-date conversion as a time-zone problem, which overcomplicates a plain local timestamp mapping.
- Ignoring the zone when the timestamp really is an instant, which produces wrong dates around midnight and daylight-saving transitions.
- Copying the first conversion snippet you find without checking what the column means.
Related reading
- How to convert java.util.Date to java.sql.Date?
- How to convert result table to JSON array in MySQL
- How to convert SQL Query result to PANDAS Data Structure?
- How to convert string into timestamp in Presto Athena?
- How to convert jsonString to JSONObject in Java
- How to convert List to Map?
- how to convert string to numerical values in mongodb
- How to convert timestamp to datetime in MySQL?
System design interview problems on this topic
- Design a Distributed OLTP Database: solution and walkthrough
- Design a Wide Column Database: solution and walkthrough
- Design a Key Value Store: solution and walkthrough
- Design a Web Cache: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.